[Sanitizer] Add rudimentary support for wide-character strings to scanf/printf interc...
[blocksruntime.git] / test / tsan / fd_dup_norace.cc
blob8826f90fc485951d3471e8737f0ec0daf0ec6679
1 // RUN: %clangxx_tsan -O1 %s -o %t && %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 printf("OK\n");
34 // CHECK-NOT: WARNING: ThreadSanitizer: data race