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