Permalink
Browse files

Merge pull request #6565

fb08d92 Make sure we re-acquire lock if a task throws (Casey Rodarmor)
  • Loading branch information...
laanwj committed Aug 19, 2015
2 parents e08a7d9 + fb08d92 commit a6f2affde878d4f16aee6aa81b0d5cf36afdbf2d
Showing with 7 additions and 5 deletions.
  1. +7 −5 src/scheduler.cpp
View
@@ -6,6 +6,7 @@
#include <assert.h>
#include <boost/bind.hpp>
+#include <boost/thread/reverse_lock.hpp>
#include <utility>
CScheduler::CScheduler() : nThreadsServicingQueue(0), stopRequested(false), stopWhenEmpty(false)
@@ -65,11 +66,12 @@ void CScheduler::serviceQueue()
Function f = taskQueue.begin()->second;
taskQueue.erase(taskQueue.begin());
- // Unlock before calling f, so it can reschedule itself or another task
- // without deadlocking:
- lock.unlock();
- f();
- lock.lock();
+ {
+ // Unlock before calling f, so it can reschedule itself or another task
+ // without deadlocking:
+ boost::reverse_lock<boost::unique_lock<boost::mutex> > rlock(lock);
+ f();
+ }
} catch (...) {
--nThreadsServicingQueue;
throw;

0 comments on commit a6f2aff

Please sign in to comment.