From 0f75e64d71baa0f3e629c2670ac25eb9b4ecf848 Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Thu, 23 Feb 2017 00:07:39 +0300 Subject: [PATCH] Detach the thread from within itself to avoid race condition Fixes: #188 --- libtransmission/platform.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libtransmission/platform.c b/libtransmission/platform.c index 3a7eed86c..1db580e72 100644 --- a/libtransmission/platform.c +++ b/libtransmission/platform.c @@ -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;