1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
/* Test program that triggers several happens-before usage errors. */
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include "unified_annotations.h"
int main(int argc, char** argv)
{
pthread_mutex_t m;
pthread_cond_t cv;
int i[64];
pthread_mutex_init(&m, NULL);
pthread_cond_init(&cv, NULL);
/* happens-after without preceding happens-before. */
U_ANNOTATE_HAPPENS_AFTER(&i);
/* happens-after on a mutex. */
U_ANNOTATE_HAPPENS_BEFORE(&m);
/* happens-after on a condition variable. */
U_ANNOTATE_HAPPENS_BEFORE(&cv);
/* condition variable operation on a h.b. annotated object. */
U_ANNOTATE_HAPPENS_BEFORE(&i);
pthread_cond_init((pthread_cond_t*)&i, NULL);
/* The sequence below is fine. */
U_ANNOTATE_NEW_MEMORY(&i, sizeof(i));
U_ANNOTATE_HAPPENS_BEFORE(&i);
U_ANNOTATE_HAPPENS_AFTER(&i);
U_ANNOTATE_NEW_MEMORY(&i, sizeof(i));
U_ANNOTATE_HAPPENS_BEFORE(&i);
U_ANNOTATE_NEW_MEMORY(&i, sizeof(i));
/* happens-before after happens-after. */
U_ANNOTATE_HAPPENS_BEFORE(&i);
U_ANNOTATE_HAPPENS_AFTER(&i);
U_ANNOTATE_HAPPENS_BEFORE(&i);
fprintf(stderr, "Done.\n");
return 0;
}
|