[llvm-commits] [compiler-rt] r170866 - /compiler-rt/trunk/lib/tsan/lit_tests/static_init6.cc

Dmitry Vyukov dvyukov at google.com
Fri Dec 21 00:08:20 PST 2012


Author: dvyukov
Date: Fri Dec 21 02:08:19 2012
New Revision: 170866

URL: http://llvm.org/viewvc/llvm-project?rev=170866&view=rev
Log:
tsan: add lit test with statically linker libstdc++

Added:
    compiler-rt/trunk/lib/tsan/lit_tests/static_init6.cc

Added: compiler-rt/trunk/lib/tsan/lit_tests/static_init6.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/static_init6.cc?rev=170866&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/lit_tests/static_init6.cc (added)
+++ compiler-rt/trunk/lib/tsan/lit_tests/static_init6.cc Fri Dec 21 02:08:19 2012
@@ -0,0 +1,42 @@
+// RUN: %clangxx_tsan -static-libstdc++ -O1 %s -o %t && %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) {
+  }
+};
+
+void *AsyncInit(void *p) {
+  return new Cache((int)(long)p);
+}
+
+Cache *CreateCache() {
+  pthread_t t;
+  pthread_create(&t, 0, AsyncInit, (void*)(long)rand());
+  void *res;
+  pthread_join(t, &res);
+  return (Cache*)res;
+}
+
+void *Thread1(void *x) {
+  static Cache *c = CreateCache();
+  if (c->x >= RAND_MAX)
+    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);
+  printf("PASS\n");
+}
+
+// CHECK-NOT: WARNING: ThreadSanitizer: data race





More information about the llvm-commits mailing list