1// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2#include "test.h"
3
4void *Thread2(void *a) {
5 barrier_wait(barrier: &barrier);
6 *(int*)a = 43;
7 return 0;
8}
9
10void *Thread(void *a) {
11 int Var = 42;
12 pthread_t t;
13 pthread_create(newthread: &t, attr: 0, start_routine: Thread2, arg: &Var);
14 Var = 42;
15 barrier_wait(barrier: &barrier);
16 pthread_join(th: t, thread_return: 0);
17 return 0;
18}
19
20int main() {
21 barrier_init(barrier: &barrier, count: 2);
22 pthread_t t;
23 pthread_create(newthread: &t, attr: 0, start_routine: Thread, arg: 0);
24 pthread_join(th: t, thread_return: 0);
25}
26
27// CHECK: WARNING: ThreadSanitizer: data race
28// CHECK: Location is stack of thread T1.
29
30

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