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
6int Global;
7
8extern "C" void AnnotateIgnoreWritesBegin(const char *f, int l);
9extern "C" void AnnotateIgnoreWritesEnd(const char *f, int l);
10extern "C" void AnnotateIgnoreReadsBegin(const char *f, int l);
11extern "C" void AnnotateIgnoreReadsEnd(const char *f, int l);
12
13void *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
22int 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