1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 #include "java.h" 3 4 void *Thread(void *p) { 5 barrier_wait(&barrier); 6 *(int*)p = 42; 7 return 0; 8 } 9 10 int main() { 11 barrier_init(&barrier, 2); 12 int const kHeapSize = 1024 * 1024; 13 jptr jheap = (jptr)malloc(kHeapSize + 8) + 8; 14 __tsan_java_init(jheap, kHeapSize); 15 const int kBlockSize = 16; 16 __tsan_java_alloc(jheap, kBlockSize); 17 pthread_t th; 18 pthread_create(&th, 0, Thread, (void*)jheap); 19 *(int*)jheap = 43; 20 barrier_wait(&barrier); 21 pthread_join(th, 0); 22 __tsan_java_free(jheap, kBlockSize); 23 fprintf(stderr, "DONE\n"); 24 return __tsan_java_fini(); 25 } 26 27 // CHECK: WARNING: ThreadSanitizer: data race 28 // CHECK: DONE 29