1// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2#include "test.h"
3
4int *g;
5
6void *Thread(void *a) {
7 int *p = 0;
8 while ((p = __atomic_load_n(&g, __ATOMIC_RELAXED)) == 0)
9 usleep(useconds: 100); // spin-wait
10 *p = 42;
11 return 0;
12}
13
14int main() {
15 pthread_t t;
16 pthread_create(newthread: &t, attr: 0, start_routine: Thread, arg: 0);
17 AnnotateIgnoreWritesBegin(__FILE__, __LINE__);
18 int *p = new int(0);
19 AnnotateIgnoreWritesEnd(__FILE__, __LINE__);
20 __atomic_store_n(&g, p, __ATOMIC_RELAXED);
21 pthread_join(th: t, thread_return: 0);
22 delete p;
23 fprintf(stderr, format: "OK\n");
24 return 0;
25}
26
27// CHECK-NOT: WARNING: ThreadSanitizer: data race
28// CHECK: OK
29

source code of compiler-rt/test/tsan/ignore_malloc.cpp