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