mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
Make sure we re-acquire lock if a task throws
This commit is contained in:
parent
1e92b27540
commit
fb08d92312
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user