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.
This commit is contained in:
Tobias Brunner 2011-06-08 10:52:05 +02:00
parent 876961cf0e
commit dcc1ad6a23
1 changed files with 2 additions and 2 deletions

View File

@ -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);