Fix threadloop
* joining must be done inside the loop, doh * a thread must release itself first in the loop, new threads have to go idle when created
This commit is contained in:
parent
cd39533899
commit
32217debe8
1 changed files with 17 additions and 12 deletions
|
|
@ -92,25 +92,30 @@ thread_loop (void* thread)
|
||||||
t->rh = &lumiera_lock_section_.rh;
|
t->rh = &lumiera_lock_section_.rh;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
lumiera_threadpool_release_thread(t);
|
||||||
|
LUMIERA_CONDITION_WAIT (t->state != LUMIERA_THREADSTATE_IDLE);
|
||||||
|
INFO (threads, "Thread awaken with state %d", t->state);
|
||||||
|
|
||||||
// NULL function means: no work to do
|
// NULL function means: no work to do
|
||||||
INFO (threads, "function %p", t->function);
|
INFO (threads, "function %p", t->function);
|
||||||
if (t->function)
|
if (t->function)
|
||||||
t->function (t->arguments);
|
t->function (t->arguments);
|
||||||
lumiera_threadpool_release_thread(t);
|
TRACE (threads, "function done");
|
||||||
LUMIERA_CONDITION_WAIT (t->state != LUMIERA_THREADSTATE_IDLE);
|
|
||||||
INFO (threads, "Thread awaken with state %d", t->state);
|
if (t->kind & LUMIERA_THREAD_JOINABLE)
|
||||||
|
{
|
||||||
|
INFO (threads, "Thread zombified");
|
||||||
|
/* move error state to data the other thread will it pick up from there */
|
||||||
|
t->arguments = (void*)lumiera_error ();
|
||||||
|
t->state = LUMIERA_THREADSTATE_ZOMBIE;
|
||||||
|
LUMIERA_CONDITION_SIGNAL;
|
||||||
|
LUMIERA_CONDITION_WAIT (t->state == LUMIERA_THREADSTATE_JOINED);
|
||||||
|
INFO (threads, "Thread joined");
|
||||||
|
}
|
||||||
|
|
||||||
} while (t->state != LUMIERA_THREADSTATE_SHUTDOWN);
|
} while (t->state != LUMIERA_THREADSTATE_SHUTDOWN);
|
||||||
// SHUTDOWN state
|
// SHUTDOWN state
|
||||||
|
|
||||||
if (t->kind & LUMIERA_THREAD_JOINABLE)
|
|
||||||
{
|
|
||||||
INFO (threads, "Thread zombified");
|
|
||||||
/* move error state to data the other thread will it pick up from there */
|
|
||||||
t->arguments = (void*)lumiera_error ();
|
|
||||||
t->state = LUMIERA_THREADSTATE_ZOMBIE;
|
|
||||||
LUMIERA_CONDITION_WAIT (t->state == LUMIERA_THREADSTATE_JOINED);
|
|
||||||
INFO (threads, "Thread joined");
|
|
||||||
}
|
|
||||||
|
|
||||||
INFO (threads, "Thread Shutdown");
|
INFO (threads, "Thread Shutdown");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue