[ASan/Win] Don't crash when ASAN_OPTIONS have disable_core=1
[blocksruntime.git] / test / tsan / ignore_malloc.cc
blob0f1fb5e3dfdcec425357f4aa98e2ec8cf13b89fb
1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2 #include <pthread.h>
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <unistd.h>
7 extern "C" {
8 void AnnotateIgnoreReadsBegin(const char *f, int l);
9 void AnnotateIgnoreReadsEnd(const char *f, int l);
10 void AnnotateIgnoreWritesBegin(const char *f, int l);
11 void AnnotateIgnoreWritesEnd(const char *f, int l);
14 int *g;
16 void *Thread(void *a) {
17 int *p = 0;
18 while ((p = __atomic_load_n(&g, __ATOMIC_RELAXED)) == 0)
19 usleep(100);
20 *p = 42;
21 return 0;
24 int main() {
25 pthread_t t;
26 pthread_create(&t, 0, Thread, 0);
27 AnnotateIgnoreWritesBegin(__FILE__, __LINE__);
28 int *p = new int(0);
29 AnnotateIgnoreWritesEnd(__FILE__, __LINE__);
30 __atomic_store_n(&g, p, __ATOMIC_RELAXED);
31 pthread_join(t, 0);
32 delete p;
33 fprintf(stderr, "OK\n");
34 return 0;
37 // CHECK-NOT: WARNING: ThreadSanitizer: data race
38 // CHECK: OK