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:
parent
d5d9b61212
commit
0f75e64d71
1 changed files with 5 additions and 1 deletions
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue