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