1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s |
2 | #include "test.h" |
3 | |
4 | volatile long X; |
5 | volatile long Y; |
6 | volatile int N1 = 2 << 10; |
7 | volatile int N2 = 32 << 10; |
8 | void (*volatile F)(); |
9 | void (*volatile G)(); |
10 | |
11 | static void foo() { |
12 | if (--N1) |
13 | return F(); |
14 | while (--N2) |
15 | G(); |
16 | } |
17 | |
18 | static void bar() { Y++; } |
19 | |
20 | void *Thread(void *p) { |
21 | F(); |
22 | X = 43; |
23 | barrier_wait(barrier: &barrier); |
24 | return 0; |
25 | } |
26 | |
27 | int main() { |
28 | barrier_init(barrier: &barrier, count: 2); |
29 | F = foo; |
30 | G = bar; |
31 | pthread_t t; |
32 | pthread_create(newthread: &t, attr: 0, start_routine: Thread, arg: 0); |
33 | barrier_wait(barrier: &barrier); |
34 | X = 43; |
35 | pthread_join(th: t, thread_return: 0); |
36 | } |
37 | |
38 | // CHECK: WARNING: ThreadSanitizer: data race |
39 | // CHECK: Write |
40 | // CHECK: #0 main |
41 | // CHECK: Previous write |
42 | // CHECK: #0 Thread |
43 | |