// 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 -o %t
// RUN: %run %t
#include <assert.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>

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() {
  create_detached_thread();
}

// 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: %run %t
#include <thread>
#include <chrono>

void func() {
      std::this_thread::sleep_for(std::chrono::milliseconds(500));
}

int main() {
      std::thread(func).detach();
}

--- 
+++ 
@@ -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();
 }
[LSan] Rewrite the test from r223419 to not use C++11.

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.

git-svn-id: c199f293c43da69278bea8e88f92242bf3aa95f7@223480 91177308-0d34-0410-b5e6-96231b3b80d8
