From dcc1ad6a23893d3e228071a306d677403509c9ea Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Wed, 8 Jun 2011 10:52:05 +0200 Subject: Prevent deadlock while shutting down thread pool. During destruction the main thread locks the mutex in processor_t and waits on a condvar for threads to have terminated. Because the mutex has also to be locked to decrement the thread count the condvar cannot be signaled before doing that as otherwise the main thread might already be waiting to join the threads while locking the mutex and thus causing a deadlock. --- src/libstrongswan/processing/processor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libstrongswan/processing/processor.c') diff --git a/src/libstrongswan/processing/processor.c b/src/libstrongswan/processing/processor.c index 31df580c1..be33fcd84 100644 --- a/src/libstrongswan/processing/processor.c +++ b/src/libstrongswan/processing/processor.c @@ -181,10 +181,10 @@ static void process_jobs(private_processor_t *this) this->working_threads[i]++; this->mutex->unlock(this->mutex); this->priority->set(this->priority, (void*)(intptr_t)i); - thread_cleanup_push((thread_cleanup_t)decrement_working_threads, - this); /* terminated threads are restarted to get a constant pool */ thread_cleanup_push((thread_cleanup_t)restart, this); + thread_cleanup_push((thread_cleanup_t)decrement_working_threads, + this); job->execute(job); thread_cleanup_pop(FALSE); thread_cleanup_pop(FALSE); -- cgit v1.2.3