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 <stdlib.h>
      4 #include <stdio.h>
      5 #include <unistd.h>
      6 
      7 extern "C" {
      8 void AnnotateIgnoreReadsBegin(const char *f, int l);
      9 void AnnotateIgnoreReadsEnd(const char *f, int l);
     10 void AnnotateIgnoreWritesBegin(const char *f, int l);
     11 void AnnotateIgnoreWritesEnd(const char *f, int l);
     12 }
     13 
     14 void *Thread(void *p) {
     15   *(int*)p = 42;
     16   return 0;
     17 }
     18 
     19 int main() {
     20   int *p = new int(0);
     21   pthread_t t;
     22   pthread_create(&t, 0, Thread, p);
     23   sleep(1);
     24   AnnotateIgnoreReadsBegin(__FILE__, __LINE__);
     25   AnnotateIgnoreWritesBegin(__FILE__, __LINE__);
     26   free(p);
     27   AnnotateIgnoreReadsEnd(__FILE__, __LINE__);
     28   AnnotateIgnoreWritesEnd(__FILE__, __LINE__);
     29   pthread_join(t, 0);
     30   fprintf(stderr, "OK\n");
     31   return 0;
     32 }
     33 
     34 // CHECK-NOT: WARNING: ThreadSanitizer: data race
     35 // CHECK: OK
     36