[compiler-rt] r253775 - [tsan] Fix detached threads in unit tests on OS X

Kuba Brecka via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 21 04:41:36 PST 2015


Author: kuba.brecka
Date: Sat Nov 21 06:41:36 2015
New Revision: 253775

URL: http://llvm.org/viewvc/llvm-project?rev=253775&view=rev
Log:
[tsan] Fix detached threads in unit tests on OS X

We need to call the intercepted version of pthread_detach. Secondly, PTHREAD_CREATE_JOINABLE and PTHREAD_CREATE_DETACHED are not 0 and 1 on OS X, so we need to properly pass these constants and not just a bool.

Differential Revision: http://reviews.llvm.org/D14837


Modified:
    compiler-rt/trunk/lib/tsan/tests/rtl/tsan_test_util_posix.cc

Modified: compiler-rt/trunk/lib/tsan/tests/rtl/tsan_test_util_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/rtl/tsan_test_util_posix.cc?rev=253775&r1=253774&r2=253775&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/tests/rtl/tsan_test_util_posix.cc (original)
+++ compiler-rt/trunk/lib/tsan/tests/rtl/tsan_test_util_posix.cc Sat Nov 21 06:41:36 2015
@@ -38,6 +38,7 @@ static __thread ReportType expect_report
 #define __interceptor_memset wrap_memset
 #define __interceptor_pthread_create wrap_pthread_create
 #define __interceptor_pthread_join wrap_pthread_join
+#define __interceptor_pthread_detach wrap_pthread_detach
 #define __interceptor_pthread_mutex_init wrap_pthread_mutex_init
 #define __interceptor_pthread_mutex_lock wrap_pthread_mutex_lock
 #define __interceptor_pthread_mutex_unlock wrap_pthread_mutex_unlock
@@ -59,6 +60,7 @@ extern "C" int __interceptor_pthread_cre
                                             void *(*start_routine)(void *),
                                             void *arg);
 extern "C" int __interceptor_pthread_join(pthread_t thread, void **value_ptr);
+extern "C" int __interceptor_pthread_detach(pthread_t thread);
 
 extern "C" int __interceptor_pthread_mutex_init(
     pthread_mutex_t *mutex, const pthread_mutexattr_t *attr);
@@ -410,7 +412,8 @@ ScopedThread::ScopedThread(bool detached
   if (!main) {
     pthread_attr_t attr;
     pthread_attr_init(&attr);
-    pthread_attr_setdetachstate(&attr, detached);
+    pthread_attr_setdetachstate(
+        &attr, detached ? PTHREAD_CREATE_DETACHED : PTHREAD_CREATE_JOINABLE);
     pthread_attr_setstacksize(&attr, 64*1024);
     __interceptor_pthread_create(&impl_->thread, &attr,
         ScopedThread::Impl::ScopedThreadCallback, impl_);
@@ -431,7 +434,7 @@ void ScopedThread::Detach() {
   CHECK(!impl_->main);
   CHECK(!impl_->detached);
   impl_->detached = true;
-  pthread_detach(impl_->thread);
+  __interceptor_pthread_detach(impl_->thread);
 }
 
 void ScopedThread::Access(void *addr, bool is_write,




More information about the llvm-commits mailing list