1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
7 void *Thread(void *p
) {
8 while (__atomic_load_n((int*)lockaddr
, __ATOMIC_RELAXED
) == 0)
9 usleep(1000); // spin-wait
10 __tsan_java_acquire(lockaddr
);
16 barrier_init(&barrier
, 2);
17 int const kHeapSize
= 1024 * 1024;
18 jptr jheap
= (jptr
)malloc(kHeapSize
+ 8) + 8;
19 __tsan_java_init(jheap
, kHeapSize
);
20 const int kBlockSize
= 16;
21 __tsan_java_alloc(jheap
, kBlockSize
);
25 pthread_create(&th
, 0, Thread
, 0);
27 __tsan_java_release(lockaddr
);
28 __atomic_store_n((int*)lockaddr
, 1, __ATOMIC_RELAXED
);
31 pthread_create(&th
, 0, Thread
, 0);
33 __tsan_java_release_store(lockaddr
);
34 __atomic_store_n((int*)lockaddr
, 1, __ATOMIC_RELAXED
);
36 __tsan_java_free(jheap
, kBlockSize
);
37 fprintf(stderr
, "DONE\n");
38 return __tsan_java_fini();
41 // CHECK-NOT: WARNING: ThreadSanitizer: data race