1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-02-22 22:20:39 +00:00

Detach the thread from within itself to avoid race condition

Fixes: #188
This commit is contained in:
Mike Gelfand 2017-02-23 00:07:39 +03:00
parent d5d9b61212
commit 0f75e64d71

View file

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