]> granicus.if.org Git - transmission/commitdiff
Detach the thread from within itself to avoid race condition
authorMike Gelfand <mikedld@mikedld.com>
Wed, 22 Feb 2017 21:07:39 +0000 (00:07 +0300)
committerMike Gelfand <mikedld@mikedld.com>
Wed, 22 Feb 2017 21:07:39 +0000 (00:07 +0300)
Fixes: #188
libtransmission/platform.c

index 3a7eed86cd25c5f8e60ca87e378921006eadc296..1db580e722eefac560e9d57bae53ef6fd9c12371 100644 (file)
@@ -98,11 +98,16 @@ tr_amInThread (const tr_thread * t)
 static ThreadFuncReturnType
 ThreadFunc (void * _t)
 {
+#ifndef _WIN32
+  pthread_detach (pthread_self ());
+#endif
+
   tr_thread * t = _t;
 
   t->func (t->arg);
 
   tr_free (t);
+
 #ifdef _WIN32
   _endthreadex (0);
   return 0;
@@ -125,7 +130,6 @@ tr_threadNew (void (*func)(void *), void * arg)
   }
 #else
   pthread_create (&t->thread, NULL, (void* (*)(void*))ThreadFunc, t);
-  pthread_detach (t->thread);
 #endif
 
   return t;