Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / fd_tid_recycled.cpp
blobd31478728bc05f6dae764ce364cb0383d7cea0d9
1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2 #include "test.h"
4 int fds[2];
6 void *ThreadCreatePipe(void *x) {
7 pipe(fds);
8 return NULL;
11 void *ThreadDummy(void *x) {
12 return NULL;
15 void *ThreadWrite(void *x) {
16 write(fds[1], "a", 1);
17 barrier_wait(&barrier);
18 return NULL;
21 void *ThreadClose(void *x) {
22 barrier_wait(&barrier);
23 close(fds[0]);
24 close(fds[1]);
25 return NULL;
28 int main() {
29 barrier_init(&barrier, 2);
30 pthread_t t_create;
31 pthread_create(&t_create, NULL, ThreadCreatePipe, NULL);
32 pthread_join(t_create, NULL);
34 for (int i = 0; i < 100; i++) {
35 pthread_t t_dummy;
36 pthread_create(&t_dummy, NULL, ThreadDummy, NULL);
37 pthread_join(t_dummy, NULL);
40 pthread_t t[2];
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
50 // CHECK: #0 close
51 // CHECK: #1 ThreadClose
52 // CHECK: Previous read of size 8
53 // CHECK: #0 write
54 // CHECK: #1 ThreadWrite