1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2 #include "test.h"
3 
4 // Test for https://llvm.org/bugs/show_bug.cgi?id=23235
5 // The bug was that synchronization between thread creation and thread start
6 // is not established if pthread_create is followed by pthread_detach.
7 
8 int x;
9 
Thread(void * a)10 void *Thread(void *a) {
11   x = 42;
12   barrier_wait(&barrier);
13   return 0;
14 }
15 
main()16 int main() {
17   barrier_init(&barrier, 2);
18   pthread_t t;
19   x = 43;
20   pthread_create(&t, 0, Thread, 0);
21   pthread_detach(t);
22   barrier_wait(&barrier);
23   fprintf(stderr, "PASS\n");
24   return 0;
25 }
26 
27 // CHECK-NOT: WARNING: ThreadSanitizer: data race
28 // CHECK: PASS
29