1 // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 #include "test.h" 3 thread(void * x)4void *thread(void *x) { 5 barrier_wait(&barrier); 6 *static_cast<int *>(x) = 2; 7 return nullptr; 8 } 9 race()10static 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 { 20 __attribute__((noinline)) XX21 X() { atexit(race); } 22 } x; 23 main()24int main() { 25 barrier_init(&barrier, 2); 26 fprintf(stderr, "DONE\n"); 27 } 28 29 // CHECK: DONE 30 // CHECK: WARNING: ThreadSanitizer: data race 31 // CHECK: Write of size 4 32 // CHECK: #0 thread 33 // CHECK: Previous write of size 4 34 // CHECK: #0 race 35 // CHECK: #1 at_exit_callback_installed_at 36 // CHECK: #2 X 37