]> git.proxmox.com Git - rustc.git/blobdiff - src/compiler-rt/test/lsan/TestCases/leak_check_before_thread_started.cc
New upstream version 1.12.0+dfsg1
[rustc.git] / src / compiler-rt / test / lsan / TestCases / leak_check_before_thread_started.cc
index 0bd4837f14c00186b83fba310abbd91bd4adc9ed..ca818e1e269cc8f7d1aac1185e7fd875803e12be 100644 (file)
@@ -4,12 +4,19 @@
 // RUN: LSAN_OPTIONS="log_pointers=1:log_threads=1" %run %t
 #include <assert.h>
 #include <pthread.h>
+#include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
+
+pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+bool flag = false;
 
 void *func(void *arg) {
-  sleep(1);
+  // This mutex will never be grabbed.
+  fprintf(stderr, "entered func()\n");
+  pthread_mutex_lock(&mutex);
   free(arg);
+  pthread_mutex_unlock(&mutex);
   return 0;
 }
 
@@ -22,6 +29,8 @@ void create_detached_thread() {
 
   void *arg = malloc(1337);
   assert(arg);
+  // This mutex is never unlocked by the main thread.
+  pthread_mutex_lock(&mutex);
   int res = pthread_create(&thread_id, &attr, func, arg);
   assert(res == 0);
 }