1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
6 void *ThreadCreatePipe(void *x
) {
11 void *ThreadDummy(void *x
) {
15 void *ThreadWrite(void *x
) {
16 write(fds
[1], "a", 1);
17 barrier_wait(&barrier
);
21 void *ThreadClose(void *x
) {
22 barrier_wait(&barrier
);
29 barrier_init(&barrier
, 2);
31 pthread_create(&t_create
, NULL
, ThreadCreatePipe
, NULL
);
32 pthread_join(t_create
, NULL
);
34 for (int i
= 0; i
< 100; i
++) {
36 pthread_create(&t_dummy
, NULL
, ThreadDummy
, NULL
);
37 pthread_join(t_dummy
, NULL
);
41 pthread_create(&t
[0], NULL
, ThreadWrite
, NULL
);
42 pthread_create(&t
[1], NULL
, ThreadClose
, NULL
);
43 pthread_join(t
[0], NULL
);
44 pthread_join(t
[1], NULL
);
47 // CHECK-NOT: CHECK failed
48 // CHECK: WARNING: ThreadSanitizer: data race
49 // CHECK: Write of size 8
51 // CHECK: #1 ThreadClose
52 // CHECK: Previous read of size 8
54 // CHECK: #1 ThreadWrite