Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / fd_dup_norace.cpp
blobe5995175bc0fdbf4e58e85cac9674f14fd1b83d3
1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2 #include <pthread.h>
3 #include <stdio.h>
4 #include <unistd.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <fcntl.h>
9 int fds[2];
11 void *Thread1(void *x) {
12 char buf;
13 read(fds[0], &buf, 1);
14 close(fds[0]);
15 return 0;
18 void *Thread2(void *x) {
19 close(fds[1]);
20 return 0;
23 int main() {
24 fds[0] = open("/dev/random", O_RDONLY);
25 fds[1] = dup2(fds[0], 100);
26 pthread_t t[2];
27 pthread_create(&t[0], NULL, Thread1, NULL);
28 pthread_create(&t[1], NULL, Thread2, NULL);
29 pthread_join(t[0], NULL);
30 pthread_join(t[1], NULL);
31 fprintf(stderr, "OK\n");
34 // CHECK-NOT: WARNING: ThreadSanitizer: data race