From 32217debe8d5b3762f06c66bd8da7c99b5ee9e03 Mon Sep 17 00:00:00 2001 From: Christian Thaeter Date: Wed, 20 Jan 2010 00:33:08 +0100 Subject: [PATCH] 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 --- src/backend/threads.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/backend/threads.c b/src/backend/threads.c index 4aeebbf23..2ec076978 100644 --- a/src/backend/threads.c +++ b/src/backend/threads.c @@ -92,25 +92,30 @@ 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); + TRACE (threads, "function done"); + + 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); // 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"); }