From fb08d92312312c6c896327d264a8e9915fdafae7 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 17 Aug 2015 17:30:46 -0400 Subject: [PATCH] Make sure we re-acquire lock if a task throws --- src/scheduler.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/scheduler.cpp b/src/scheduler.cpp index d5bb588b71..06115f5619 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -6,6 +6,7 @@ #include #include +#include #include 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 > rlock(lock); + f(); + } } catch (...) { --nThreadsServicingQueue; throw;