1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
7 // dup2(oldfd, newfd) races with close(newfd).
11 void *Thread(void *x
) {
12 barrier_wait(&barrier
);
14 exit(printf("close failed\n"));
19 barrier_init(&barrier
, 2);
20 fd
= open("/dev/random", O_RDONLY
);
21 int fd2
= open("/dev/random", O_RDONLY
);
22 if (fd
== -1 || fd2
== -1)
23 exit(printf("open failed\n"));
25 pthread_create(&th
, 0, Thread
, 0);
26 if (dup2(fd2
, fd
) == -1)
27 exit(printf("dup2 failed\n"));
28 barrier_wait(&barrier
);
30 fprintf(stderr
, "DONE\n");
33 // CHECK: WARNING: ThreadSanitizer: data race