blob: 25ffd47e6cc24d50a162b811b86af2369abf7fd5 [file] [log] [blame]
bartea2a03c2010-03-21 17:24:47 +00001// Test for ANNOTATE_BENIGN_RACE_STATIC() and ANNOTATE_UNPROTECTED_READ().
2
3
4#include <pthread.h> /* pthread_create() */
5#include <stdio.h> /* fprintf() */
6#include "../../drd/drd.h"
7
8
9/* Local variables. */
10
11static int s_i;
12static volatile int s_j;
13
14ANNOTATE_BENIGN_RACE_STATIC(s_i, "Benign because duplicate assignment.");
15
16
17/* Local functions. */
18
bart9a020882010-09-11 10:07:56 +000019static inline void AnnotateIgnoreReadsBegin() { ANNOTATE_IGNORE_READS_BEGIN(); }
20static inline void AnnotateIgnoreReadsEnd() { ANNOTATE_IGNORE_READS_END(); }
21
bartea2a03c2010-03-21 17:24:47 +000022static void* thread_func(void*)
23{
bart0af2b992010-09-13 17:44:10 +000024#if defined(__powerpc__) && __GNUC__ -0 == 4 && __GNUC_MINOR__ -0 == 3 \
25 && __GNUC_PATCHLEVEL__ -0 == 0
bart9a020882010-09-11 10:07:56 +000026 AnnotateIgnoreReadsBegin();
27 int i = s_j;
28 AnnotateIgnoreReadsEnd();
29 s_i = i;
bart0af2b992010-09-13 17:44:10 +000030#else
31 s_i = ANNOTATE_UNPROTECTED_READ(s_j);
32#endif
bartea2a03c2010-03-21 17:24:47 +000033 return 0;
34}
35
36int main(int argc, char** argv)
37{
38 pthread_t tid;
39
40 pthread_create(&tid, 0, thread_func, NULL);
41 s_j++;
42 s_i = s_j;
43 pthread_join(tid, NULL);
44
45 fprintf(stderr, "Done.\n");
46
47 return 0;
48}