2014-05-01 05:34:17 +08:00
|
|
|
// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
|
2012-12-21 21:31:07 +08:00
|
|
|
#include "java.h"
|
|
|
|
|
|
|
|
jptr varaddr;
|
|
|
|
jptr lockaddr;
|
|
|
|
|
|
|
|
void *Thread(void *p) {
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_wait(&barrier);
|
2012-12-21 21:31:07 +08:00
|
|
|
__tsan_java_mutex_read_lock(lockaddr);
|
|
|
|
*(int*)varaddr = 42;
|
|
|
|
__tsan_java_mutex_read_unlock(lockaddr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_init(&barrier, 2);
|
2012-12-21 21:31:07 +08:00
|
|
|
int const kHeapSize = 1024 * 1024;
|
2014-07-09 04:01:12 +08:00
|
|
|
jptr jheap = (jptr)malloc(kHeapSize + 8) + 8;
|
|
|
|
__tsan_java_init(jheap, kHeapSize);
|
2012-12-21 21:31:07 +08:00
|
|
|
const int kBlockSize = 16;
|
2014-07-09 04:01:12 +08:00
|
|
|
__tsan_java_alloc(jheap, kBlockSize);
|
|
|
|
varaddr = jheap;
|
|
|
|
lockaddr = jheap + 8;
|
2012-12-21 21:31:07 +08:00
|
|
|
pthread_t th;
|
|
|
|
pthread_create(&th, 0, Thread, 0);
|
|
|
|
__tsan_java_mutex_lock(lockaddr);
|
|
|
|
*(int*)varaddr = 43;
|
|
|
|
__tsan_java_mutex_unlock(lockaddr);
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_wait(&barrier);
|
2012-12-21 21:31:07 +08:00
|
|
|
pthread_join(th, 0);
|
2014-07-09 04:01:12 +08:00
|
|
|
__tsan_java_free(jheap, kBlockSize);
|
2016-03-02 19:54:07 +08:00
|
|
|
printf("DONE\n");
|
2012-12-21 21:31:07 +08:00
|
|
|
return __tsan_java_fini();
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-NOT: WARNING: ThreadSanitizer: data race
|
2014-07-09 04:01:12 +08:00
|
|
|
// CHECK: DONE
|