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