1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
7 void *Thread(void *p
) {
8 __tsan_java_mutex_lock(lockaddr
);
9 __tsan_java_mutex_lock(lockaddr
);
11 int rec
= __tsan_java_mutex_unlock_rec(lockaddr
);
13 fprintf(stderr
, "FAILED 0 rec=%d\n", rec
);
16 barrier_wait(&barrier
);
17 barrier_wait(&barrier
);
18 __tsan_java_mutex_lock_rec(lockaddr
, rec
);
19 if (*(int*)varaddr
!= 43) {
20 fprintf(stderr
, "FAILED 3 var=%d\n", *(int*)varaddr
);
23 __tsan_java_mutex_unlock(lockaddr
);
24 __tsan_java_mutex_unlock(lockaddr
);
29 barrier_init(&barrier
, 2);
30 int const kHeapSize
= 1024 * 1024;
31 jptr jheap
= (jptr
)malloc(kHeapSize
+ 8) + 8;
32 __tsan_java_init(jheap
, kHeapSize
);
33 const int kBlockSize
= 16;
34 __tsan_java_alloc(jheap
, kBlockSize
);
39 pthread_create(&th
, 0, Thread
, 0);
40 barrier_wait(&barrier
);
41 __tsan_java_mutex_lock(lockaddr
);
42 if (*(int*)varaddr
!= 42) {
43 fprintf(stderr
, "FAILED 1 var=%d\n", *(int*)varaddr
);
47 __tsan_java_mutex_unlock(lockaddr
);
48 barrier_wait(&barrier
);
50 __tsan_java_free(jheap
, kBlockSize
);
51 fprintf(stderr
, "DONE\n");
52 return __tsan_java_fini();
55 // CHECK-NOT: WARNING: ThreadSanitizer: data race