[LSan] Rewrite the test from r223419 to not use C++11.
authorSergey Matveev <earthdok@google.com>
Fri, 5 Dec 2014 17:21:43 +0000 (17:21 +0000)
committerSergey Matveev <earthdok@google.com>
Fri, 5 Dec 2014 17:21:43 +0000 (17:21 +0000)
This was causing build failures on llvm-clang-lld-x86_64-centos-6.5 for some
reason. Anyway, the new way is better because we no longer rely on std::thread
implementation details.

llvm-svn: 223480

compiler-rt/test/lsan/TestCases/leak_check_before_thread_started.cc

index a2357e0..891cd69 100644 (file)
@@ -1,15 +1,32 @@
 // Regression test for http://llvm.org/bugs/show_bug.cgi?id=21621
 // This test relies on timing between threads, so any failures will be flaky.
 // RUN: LSAN_BASE="use_stacks=0:use_registers=0"
-// RUN: %clangxx_lsan %s -std=c++11 -o %t
+// RUN: %clangxx_lsan %s -o %t
 // RUN: %run %t
-#include <thread>
-#include <chrono>
+#include <assert.h>
+#include <pthread.h>
+#include <stdlib.h>
+#include <unistd.h>
 
-void func() {
-      std::this_thread::sleep_for(std::chrono::milliseconds(500));
+void *func(void *arg) {
+  sleep(1);
+  free(arg);
+  return 0;
+}
+
+void create_detached_thread() {
+  pthread_t thread_id;
+  pthread_attr_t attr;
+
+  pthread_attr_init(&attr);
+  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
+  void *arg = malloc(1337);
+  assert(arg);
+  int res = pthread_create(&thread_id, &attr, func, arg);
+  assert(res == 0);
 }
 
 int main() {
-      std::thread(func).detach();
+  create_detached_thread();
 }