Home | History | Annotate | Download | only in tsan
      1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
      2 #include "test.h"
      3 
      4 extern "C" {
      5 void AnnotateIgnoreReadsBegin(const char *f, int l);
      6 void AnnotateIgnoreReadsEnd(const char *f, int l);
      7 void AnnotateIgnoreWritesBegin(const char *f, int l);
      8 void AnnotateIgnoreWritesEnd(const char *f, int l);
      9 }
     10 
     11 void *Thread(void *p) {
     12   *(int*)p = 42;
     13   barrier_wait(&barrier);
     14   return 0;
     15 }
     16 
     17 int main() {
     18   barrier_init(&barrier, 2);
     19   int *p = new int(0);
     20   pthread_t t;
     21   pthread_create(&t, 0, Thread, p);
     22   barrier_wait(&barrier);
     23   AnnotateIgnoreReadsBegin(__FILE__, __LINE__);
     24   AnnotateIgnoreWritesBegin(__FILE__, __LINE__);
     25   free(p);
     26   AnnotateIgnoreReadsEnd(__FILE__, __LINE__);
     27   AnnotateIgnoreWritesEnd(__FILE__, __LINE__);
     28   pthread_join(t, 0);
     29   fprintf(stderr, "OK\n");
     30   return 0;
     31 }
     32 
     33 // CHECK-NOT: WARNING: ThreadSanitizer: data race
     34 // CHECK: OK
     35