aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/processing/processor.c
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2011-06-08 10:52:05 +0200
committerTobias Brunner <tobias@strongswan.org>2011-06-08 11:44:42 +0200
commitdcc1ad6a23893d3e228071a306d677403509c9ea (patch)
treeca1a1847490e3f012bcbca2252f39a749b221953 /src/libstrongswan/processing/processor.c
parent876961cf0e4edb4708aea359a578b053d6e6d5b0 (diff)
downloadstrongswan-dcc1ad6a23893d3e228071a306d677403509c9ea.tar.bz2
strongswan-dcc1ad6a23893d3e228071a306d677403509c9ea.tar.xz
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.
Diffstat (limited to 'src/libstrongswan/processing/processor.c')
-rw-r--r--src/libstrongswan/processing/processor.c4
1 files changed, 2 insertions, 2 deletions
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);