Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / fd_close_race.cpp
blob549f1dc2767237112d2bc2e3bace5f7f85d4932b
1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2 #include "test.h"
3 #include <fcntl.h>
4 #include <sys/stat.h>
5 #include <sys/types.h>
7 void *Thread(void *arg) {
8 char buf;
9 read((long)arg, &buf, 1);
10 barrier_wait(&barrier);
11 return NULL;
14 int main() {
15 barrier_init(&barrier, 2);
16 int fd = open("/dev/random", O_RDONLY);
17 pthread_t t;
18 pthread_create(&t, NULL, Thread, (void *)(long)fd);
19 barrier_wait(&barrier);
20 close(fd);
21 pthread_join(t, NULL);
22 fprintf(stderr, "DONE\n");
25 // CHECK: WARNING: ThreadSanitizer: data race
26 // CHECK: DONE