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 | |
10 | void *Thread(void *a) { |
11 | x = 42; |
12 | barrier_wait(barrier: &barrier); |
13 | return 0; |
14 | } |
15 | |
16 | int main() { |
17 | barrier_init(barrier: &barrier, count: 2); |
18 | pthread_t t; |
19 | x = 43; |
20 | pthread_create(newthread: &t, attr: 0, start_routine: Thread, arg: 0); |
21 | pthread_detach(th: t); |
22 | barrier_wait(barrier: &barrier); |
23 | fprintf(stderr, format: "PASS\n"); |
24 | return 0; |
25 | } |
26 | |
27 | // CHECK-NOT: WARNING: ThreadSanitizer: data race |
28 | // CHECK: PASS |
29 |