Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / thread_detach2.c
blob5ee94e9a967babe486bcfcc8e16f9b67744f67e0
1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2 #include "test.h"
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.
8 int x;
10 void *Thread(void *a) {
11 x = 42;
12 barrier_wait(&barrier);
13 return 0;
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;
27 // CHECK-NOT: WARNING: ThreadSanitizer: data race
28 // CHECK: PASS