-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
I've been seeing some hangs in ./test threading
I think one problem can be fixed by this patch:
diff --git a/util/thread_pool.cpp b/util/thread_pool.cpp
index e20aab1..b95bc1d 100644
— a/util/thread_pool.cpp
+++ b/util/thread_pool.cpp
@@ -99,8 +99,8 @@ ThreadPool::~ThreadPool(){
}
void ThreadPool::join(){
+ boostlock lock(_mutex);
while(_tasksRemaining)
}
As is, join() might check _tasksRemaining while task_done() has the mutex but before task_done() has decremented _tasksRemaining. So race condition is:
1) task_done() grabs _mutex
2) join() sees that _tasksRemaining > 0, then waits for _mutex
3) task_done() decrements _tasksRemaining and signals _condition
4) join() grabs _mutex and waits for _condition
Not that familiar w/ the code, let me know what you think.