Home | History | Annotate | Download | only in tsan
      1 // RUN: %clang_tsan -O1 %s -o %t && TSAN_OPTIONS="$TSAN_OPTIONS halt_on_error=1" %deflake %run %t | FileCheck %s
      2 #include <pthread.h>
      3 #include <stdio.h>
      4 #include <unistd.h>
      5 
      6 int X;
      7 
      8 void *Thread(void *x) {
      9   sleep(1);
     10   X = 42;
     11   return 0;
     12 }
     13 
     14 int main() {
     15   fprintf(stderr, "BEFORE\n");
     16   pthread_t t;
     17   pthread_create(&t, 0, Thread, 0);
     18   X = 43;
     19   pthread_join(t, 0);
     20   fprintf(stderr, "AFTER\n");
     21   return 0;
     22 }
     23 
     24 // CHECK: BEFORE
     25 // CHECK: WARNING: ThreadSanitizer: data race
     26 // CHECK-NOT: AFTER
     27 
     28