memcheck/tests/sh-mem-random.c: Set huge_addr to 240GB
[valgrind.git] / drd / tests / annotate_hb_race.c
blob4aa5a380e861fbdd2f11787b4d16ffd5b3a3facc
1 /*
2 * Test program with happens-before / happens-after annotations that triggers
3 * a data race. The data race will only be reported if happens-after
4 * annotations that occur in different threads are not totally ordered. Or:
5 * this is a test for the implementation of ordering annotations.
6 */
9 #include <stdio.h>
10 #include <pthread.h>
11 #include "unified_annotations.h"
14 static int s_i;
17 static void* thread_func(void* arg)
19 int i;
21 U_ANNOTATE_HAPPENS_AFTER(&s_i);
22 i = s_i;
23 U_ANNOTATE_HAPPENS_AFTER(&s_i);
24 *(int*)arg = i;
25 return NULL;
28 int main(int argc, char** argv)
30 const struct timespec delay = { 0, 100 * 1000 * 1000 };
31 pthread_t tid[2];
32 int result[2];
34 U_ANNOTATE_HAPPENS_BEFORE(&s_i);
35 pthread_create(&tid[0], 0, thread_func, &result[0]);
36 pthread_create(&tid[1], 0, thread_func, &result[1]);
38 nanosleep(&delay, 0);
40 s_i = 1;
42 pthread_join(tid[0], NULL);
43 pthread_join(tid[1], NULL);
45 fprintf(stderr, "Done.\n");
47 return 0;