37 lines · cpp
1// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s2#include "test.h"3 4void *thread(void *x) {5 barrier_wait(&barrier);6 *static_cast<int *>(x) = 2;7 return nullptr;8}9 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 19struct X {20 __attribute__((noinline))21 X() { atexit(race); }22} x;23 24int main() {25 barrier_init(&barrier, 2);26 fprintf(stderr, "DONE\n");27}28 29// CHECK: DONE30// CHECK: WARNING: ThreadSanitizer: data race31// CHECK: Write of size 432// CHECK: #0 thread33// CHECK: Previous write of size 434// CHECK: #0 race35// CHECK: #1 at_exit_callback_installed_at36// CHECK: #2 X37