]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/valgrind/src/valgrind-3.6.0-svn/drd/tests/annotate_hb_race.c
update
[l4.git] / l4 / pkg / valgrind / src / valgrind-3.6.0-svn / drd / tests / annotate_hb_race.c
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  */
7
8
9 #include <stdio.h>
10 #include <pthread.h>
11 #include "unified_annotations.h"
12
13
14 static int s_i;
15
16
17 static void* thread_func(void* arg)
18 {
19   int i;
20
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;
26 }
27
28 int main(int argc, char** argv)
29 {
30   pthread_t tid[2];
31   int result[2];
32
33   U_ANNOTATE_HAPPENS_BEFORE(&s_i);
34   pthread_create(&tid[0], 0, thread_func, &result[0]);
35   pthread_create(&tid[1], 0, thread_func, &result[1]);
36   s_i = 1;
37
38   pthread_join(tid[0], NULL);
39   pthread_join(tid[1], NULL);
40
41   fprintf(stderr, "Done.\n");
42
43   return 0;
44 }
45
46 /*
47  * Local variables:
48  * c-basic-offset: 2
49  * End:
50  */