Home | History | Annotate | Download | only in tsan
      1 // RUN: %clang_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 Global;
      7 
      8 extern "C" void AnnotateIgnoreWritesBegin(const char *f, int l);
      9 extern "C" void AnnotateIgnoreWritesEnd(const char *f, int l);
     10 extern "C" void AnnotateIgnoreReadsBegin(const char *f, int l);
     11 extern "C" void AnnotateIgnoreReadsEnd(const char *f, int l);
     12 
     13 void *Thread(void *x) {
     14   AnnotateIgnoreWritesBegin(__FILE__, __LINE__);
     15   AnnotateIgnoreReadsBegin(__FILE__, __LINE__);
     16   Global = 42;
     17   AnnotateIgnoreReadsEnd(__FILE__, __LINE__);
     18   AnnotateIgnoreWritesEnd(__FILE__, __LINE__);
     19   return 0;
     20 }
     21 
     22 int main() {
     23   pthread_t t;
     24   pthread_create(&t, 0, Thread, 0);
     25   sleep(1);
     26   Global = 43;
     27   pthread_join(t, 0);
     28   printf("OK\n");
     29 }
     30 
     31 // CHECK-NOT: WARNING: ThreadSanitizer: data race
     32