Home | History | Annotate | Download | only in lit_tests
      1 // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s
      2 #include <pthread.h>
      3 #include <unistd.h>
      4 
      5 int X = 0;
      6 
      7 void MySleep() {
      8   sleep(1);
      9 }
     10 
     11 void *Thread(void *p) {
     12   MySleep();  // Assume the main thread has done the write.
     13   X = 42;
     14   return 0;
     15 }
     16 
     17 int main() {
     18   pthread_t t;
     19   pthread_create(&t, 0, Thread, 0);
     20   X = 43;
     21   pthread_join(t, 0);
     22   return 0;
     23 }
     24 
     25 // CHECK: WARNING: ThreadSanitizer: data race
     26 // ...
     27 // CHECK:   As if synchronized via sleep:
     28 // CHECK-NEXT:     #0 sleep
     29 // CHECK-NEXT:     #1 MySleep
     30 // CHECK-NEXT:     #2 Thread
     31