1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s 2 #include "java.h" 3 Thread(void * p)4void *Thread(void *p) { 5 sleep(1); 6 __tsan_java_finalize(); 7 *(int*)p = 42; 8 return 0; 9 } 10 main()11int main() { 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 pthread_join(th, 0); 21 __tsan_java_free(jheap, kBlockSize); 22 fprintf(stderr, "DONE\n"); 23 return __tsan_java_fini(); 24 } 25 26 // CHECK-NOT: WARNING: ThreadSanitizer: data race 27 // CHECK: DONE 28