Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / annotate_happens_before.cpp
blob86a8669681e156ee18162a64f3923a2626eeebb1
1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2 #include "test.h"
4 /*
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.
12 int Global;
14 void *Thread1(void *x) {
15 barrier_wait(&barrier);
16 ANNOTATE_HAPPENS_AFTER(&barrier);
17 Global++;
18 return NULL;
21 void *Thread2(void *x) {
22 Global--;
23 ANNOTATE_HAPPENS_BEFORE(&barrier);
24 barrier_wait(&barrier);
25 return NULL;
28 int main() {
29 barrier_init(&barrier, 2);
30 pthread_t t[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");
36 return 0;
39 // CHECK-NOT: WARNING: ThreadSanitizer: data race
40 // CHECK: DONE