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