1// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2#include "test.h"
3
4int Global;
5int WTFGlobal;
6
7void *Thread(void *x) {
8 Global = 42;
9 WTFGlobal = 142;
10 barrier_wait(barrier: &barrier);
11 return 0;
12}
13
14int main() {
15 barrier_init(barrier: &barrier, count: 2);
16 ANNOTATE_BENIGN_RACE(Global);
17 WTF_ANNOTATE_BENIGN_RACE(WTFGlobal);
18 pthread_t t;
19 pthread_create(newthread: &t, attr: 0, start_routine: Thread, arg: 0);
20 barrier_wait(barrier: &barrier);
21 Global = 43;
22 WTFGlobal = 143;
23 pthread_join(th: t, thread_return: 0);
24 fprintf(stderr, format: "OK\n");
25}
26
27// CHECK-NOT: WARNING: ThreadSanitizer: data race
28

source code of compiler-rt/test/tsan/benign_race.cpp