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