summaryrefslogtreecommitdiff
path: root/test/tsan/static_init4.cpp
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2019-08-02 07:18:07 +0000
committerFangrui Song <maskray@google.com>2019-08-02 07:18:07 +0000
commit681afdf34bb16d1877e984d157dfd389a79a4256 (patch)
tree4e3f851ec5cfff68846a11843577ed58d4fdd430 /test/tsan/static_init4.cpp
parent871e3822d6679af8f7cfa763b65258e47f2d8d69 (diff)
downloadcompiler-rt-681afdf34bb16d1877e984d157dfd389a79a4256.tar.gz
compiler-rt: Rename .cc file in test/tsan to .cpp
Like r367463, but for test/tsan. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@367656 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/tsan/static_init4.cpp')
-rw-r--r--test/tsan/static_init4.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/tsan/static_init4.cpp b/test/tsan/static_init4.cpp
new file mode 100644
index 000000000..c8da78364
--- /dev/null
+++ b/test/tsan/static_init4.cpp
@@ -0,0 +1,37 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+#include <pthread.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sched.h>
+
+struct Cache {
+ int x;
+ explicit Cache(int x)
+ : x(x) {
+ }
+};
+
+int g_other;
+
+Cache *CreateCache() {
+ g_other = rand();
+ return new Cache(rand());
+}
+
+void *Thread1(void *x) {
+ static Cache *c = CreateCache();
+ if (c->x == g_other)
+ exit(1);
+ return 0;
+}
+
+int main() {
+ pthread_t t[2];
+ pthread_create(&t[0], 0, Thread1, 0);
+ pthread_create(&t[1], 0, Thread1, 0);
+ pthread_join(t[0], 0);
+ pthread_join(t[1], 0);
+ fprintf(stderr, "PASS\n");
+}
+
+// CHECK-NOT: WARNING: ThreadSanitizer: data race