mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
~CThreadPool(): Handle spurious wakeups
From pthread_cond_wait()'s man page: When using condition variables there is always a boolean predicate involving shared variables associated with each condition wait that is true if the thread should proceed. Spurious wakeups from the pthread_cond_wait() or pthread_cond_timedwait() functions may occur. Since the return from pthread_cond_wait() or pthread_cond_timedwait() does not imply anything about the value of this predicate, the predicate should be re-evaluated upon such return. Fix ~CThreadPool() to account for this possibility. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
committed by
J-P Nurmi
parent
ac3570f18a
commit
fd34f84bfd
@@ -87,7 +87,7 @@ CThreadPool::~CThreadPool() {
|
||||
CMutexLocker guard(m_mutex);
|
||||
m_done = true;
|
||||
|
||||
if (m_num_threads > 0) {
|
||||
while (m_num_threads > 0) {
|
||||
m_cond.broadcast();
|
||||
m_exit_cond.wait(m_mutex);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user