Skip to content

Commit a6f2aff

Browse files
committed
Merge pull request #6565
fb08d92 Make sure we re-acquire lock if a task throws (Casey Rodarmor)
2 parents e08a7d9 + fb08d92 commit a6f2aff

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/scheduler.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <assert.h>
88
#include <boost/bind.hpp>
9+
#include <boost/thread/reverse_lock.hpp>
910
#include <utility>
1011

1112
CScheduler::CScheduler() : nThreadsServicingQueue(0), stopRequested(false), stopWhenEmpty(false)
@@ -65,11 +66,12 @@ void CScheduler::serviceQueue()
6566
Function f = taskQueue.begin()->second;
6667
taskQueue.erase(taskQueue.begin());
6768

68-
// Unlock before calling f, so it can reschedule itself or another task
69-
// without deadlocking:
70-
lock.unlock();
71-
f();
72-
lock.lock();
69+
{
70+
// Unlock before calling f, so it can reschedule itself or another task
71+
// without deadlocking:
72+
boost::reverse_lock<boost::unique_lock<boost::mutex> > rlock(lock);
73+
f();
74+
}
7375
} catch (...) {
7476
--nThreadsServicingQueue;
7577
throw;

0 commit comments

Comments
 (0)