[SERVER-532] wait forever in thread_pool.cpp Created: 11/Jan/10  Updated: 12/Jul/16  Resolved: 13/Jan/10

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 1.3.1

Type: Bug Priority: Major - P3
Reporter: Aaron Staple Assignee: Mathias Stearn
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

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)

{ - boostlock lock(_mutex); _condition.wait(lock); }

}

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.



 Comments   
Comment by auto [ 12/Jan/10 ]

Author:

{'name': 'Mathias Stearn', 'email': 'mathias@10gen.com'}

Message: Fix race condition. SERVER-532
http://github.com/mongodb/mongo/commit/494d9678b9d06b5b6e7b99fdaf36cf4c0d559e91

Generated at Thu Feb 08 02:54:24 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.