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