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 6 int fds[2]; 7 int X; 8 9 void *Thread1(void *x) { 10 X = 42; 11 write(fds[1], "a", 1); 12 return NULL; 13 } 14 15 void *Thread2(void *x) { 16 char buf; 17 while (read(fds[0], &buf, 1) != 1) { 18 } 19 X = 43; 20 return NULL; 21 } 22 23 int main() { 24 pipe(fds); 25 pthread_t t[2]; 26 pthread_create(&t[0], NULL, Thread1, NULL); 27 pthread_create(&t[1], NULL, Thread2, NULL); 28 pthread_join(t[0], NULL); 29 pthread_join(t[1], NULL); 30 fprintf(stderr, "OK\n"); 31 } 32 33 // CHECK-NOT: WARNING: ThreadSanitizer: data race 34