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> 8 9 int fds[2]; 10 11 void *Thread1(void *x) { 12 char buf; 13 read(fds[0], &buf, 1); 14 close(fds[0]); 15 return 0; 16 } 17 18 void *Thread2(void *x) { 19 close(fds[1]); 20 return 0; 21 } 22 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"); 32 } 33 34 // CHECK-NOT: WARNING: ThreadSanitizer: data race 35