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:
Christian Thaeter 2010-01-20 00:33:08 +01:00
parent cd39533899
commit 32217debe8

View file

@ -92,15 +92,15 @@ thread_loop (void* thread)
t->rh = &lumiera_lock_section_.rh;
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
INFO (threads, "function %p", t->function);
if (t->function)
t->function (t->arguments);
lumiera_threadpool_release_thread(t);
LUMIERA_CONDITION_WAIT (t->state != LUMIERA_THREADSTATE_IDLE);
INFO (threads, "Thread awaken with state %d", t->state);
} while (t->state != LUMIERA_THREADSTATE_SHUTDOWN);
// SHUTDOWN state
TRACE (threads, "function done");
if (t->kind & LUMIERA_THREAD_JOINABLE)
{
@ -108,10 +108,15 @@ thread_loop (void* thread)
/* 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);
// SHUTDOWN state
INFO (threads, "Thread Shutdown");
}
TODO ("no error must be pending here, else do app shutdown");