diff options
| author | Wladimir J. van der Laan <[email protected]> | 2015-08-19 16:26:37 +0200 |
|---|---|---|
| committer | Wladimir J. van der Laan <[email protected]> | 2015-08-19 16:27:40 +0200 |
| commit | a6f2affde878d4f16aee6aa81b0d5cf36afdbf2d (patch) | |
| tree | 587a8335fc63f6ba4ca7e78163f5fa35fb5b6f03 /src | |
| parent | Merge pull request #6561 (diff) | |
| parent | Make sure we re-acquire lock if a task throws (diff) | |
| download | discoin-a6f2affde878d4f16aee6aa81b0d5cf36afdbf2d.tar.xz discoin-a6f2affde878d4f16aee6aa81b0d5cf36afdbf2d.zip | |
Merge pull request #6565
fb08d92 Make sure we re-acquire lock if a task throws (Casey Rodarmor)
Diffstat (limited to 'src')
| -rw-r--r-- | src/scheduler.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/scheduler.cpp b/src/scheduler.cpp index d5bb588b7..06115f561 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -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; |