Browse Source

Merge pull request #6565

fb08d92 Make sure we re-acquire lock if a task throws (Casey Rodarmor)
0.13
Wladimir J. van der Laan 9 years ago
parent
commit
a6f2affde8
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
  1. 12
      src/scheduler.cpp

12
src/scheduler.cpp

@ -6,6 +6,7 @@
#include <assert.h> #include <assert.h>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/thread/reverse_lock.hpp>
#include <utility> #include <utility>
CScheduler::CScheduler() : nThreadsServicingQueue(0), stopRequested(false), stopWhenEmpty(false) CScheduler::CScheduler() : nThreadsServicingQueue(0), stopRequested(false), stopWhenEmpty(false)
@ -65,11 +66,12 @@ void CScheduler::serviceQueue()
Function f = taskQueue.begin()->second; Function f = taskQueue.begin()->second;
taskQueue.erase(taskQueue.begin()); taskQueue.erase(taskQueue.begin());
// Unlock before calling f, so it can reschedule itself or another task {
// without deadlocking: // Unlock before calling f, so it can reschedule itself or another task
lock.unlock(); // without deadlocking:
f(); boost::reverse_lock<boost::unique_lock<boost::mutex> > rlock(lock);
lock.lock(); f();
}
} catch (...) { } catch (...) {
--nThreadsServicingQueue; --nThreadsServicingQueue;
throw; throw;

Loading…
Cancel
Save