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