1 // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2 #include "test.h"
3 
thread(void * x)4 void *thread(void *x) {
5   barrier_wait(&barrier);
6   *static_cast<int *>(x) = 2;
7   return nullptr;
8 }
9 
race()10 static void race() {
11   int data = 0;
12   pthread_t t;
13   pthread_create(&t, nullptr, thread, &data);
14   data = 1;
15   barrier_wait(&barrier);
16   pthread_join(t, nullptr);
17 }
18 
19 struct X {
XX20   X() { atexit(race); }
21 } x;
22 
main()23 int main() {
24   barrier_init(&barrier, 2);
25   fprintf(stderr, "DONE\n");
26 }
27 
28 // CHECK: DONE
29 // CHECK: WARNING: ThreadSanitizer: data race
30