]> Git Repo - VerusCoin.git/commitdiff
Make sure we re-acquire lock if a task throws
authorCasey Rodarmor <[email protected]>
Mon, 17 Aug 2015 21:30:46 +0000 (17:30 -0400)
committerLuke Dashjr <[email protected]>
Tue, 22 Sep 2015 00:43:13 +0000 (00:43 +0000)
src/scheduler.cpp

index d5bb588b712961aa7eb8a1bb4c452ed6452af8b3..06115f5619753178f47f7e5a41f0208678f3f543 100644 (file)
@@ -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;
This page took 0.025923 seconds and 4 git commands to generate.