Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / fd_close_norace3.cpp
blobeab8cd515ab3e2ec6e3e61e1d500a7775129c4c5
1 // RUN: %clangxx_tsan -O1 %s -o %t && %env_tsan_opts=flush_memory_ms=1 %run %t 2>&1 | FileCheck %s
2 #include "test.h"
3 #include <fcntl.h>
4 #include <sys/stat.h>
5 #include <sys/types.h>
6 #include <unistd.h>
8 void *Thread(void *stop) {
9 while (!__atomic_load_n((int *)stop, __ATOMIC_RELAXED))
10 close(open("/dev/null", O_RDONLY));
11 return 0;
14 int main() {
15 int stop = 0;
16 const int kThreads = 10;
17 pthread_t th[kThreads];
18 for (int i = 0; i < kThreads; i++)
19 pthread_create(&th[i], 0, Thread, &stop);
20 sleep(5);
21 __atomic_store_n(&stop, 1, __ATOMIC_RELAXED);
22 for (int i = 0; i < kThreads; i++)
23 pthread_join(th[i], 0);
24 fprintf(stderr, "DONE\n");
27 // CHECK-NOT: WARNING: ThreadSanitizer: data race
28 // CHECK: DONE