You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

33 lines
1.1 KiB

From 2f4488c2a4f2d6b130ded560efa06680bfd8a185 Mon Sep 17 00:00:00 2001
From: Uli Schlachter <psychon@znc.in>
Date: Sat, 14 Feb 2015 19:41:26 +0100
Subject: [PATCH] ~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>
---
src/Threads.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- a/src/Threads.cpp
+++ b/src/Threads.cpp
@@ -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);
}