1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
5 Annotations usage example.
7 Tsan does not see synchronization in barrier_wait.
8 ANNOTATE_HAPPENS_BEFORE/AFTER communicate the synchronization to tsan
9 and prevent the race report.
14 void *Thread1(void *x
) {
15 barrier_wait(&barrier
);
16 ANNOTATE_HAPPENS_AFTER(&barrier
);
21 void *Thread2(void *x
) {
23 ANNOTATE_HAPPENS_BEFORE(&barrier
);
24 barrier_wait(&barrier
);
29 barrier_init(&barrier
, 2);
31 pthread_create(&t
[0], NULL
, Thread1
, NULL
);
32 pthread_create(&t
[1], NULL
, Thread2
, NULL
);
33 pthread_join(t
[0], NULL
);
34 pthread_join(t
[1], NULL
);
35 fprintf(stderr
, "DONE\n");
39 // CHECK-NOT: WARNING: ThreadSanitizer: data race