Fix intermittent hang issue in scheduler_tests

Don't clear `stopRequested` and `stopWhenEmpty` at the top of
`serviceQueue`, as this results in a race condition: on systems under
heavy load, some of the threads only get scheduled on the CPU when the
other threads have already finished their work. This causes the flags to
be cleared post-hoc and thus those threads to wait forever.

The potential drawback of this change is that the scheduler cannot be
restarted after being stopped (an explicit reset would be needed), but
we don't use this functionality anyway.
This commit is contained in:
Wladimir J. van der Laan 2015-05-21 18:57:10 +02:00
parent 0d862c2739
commit bdcf5dea7c

View file

@ -29,8 +29,6 @@ void CScheduler::serviceQueue()
{ {
boost::unique_lock<boost::mutex> lock(newTaskMutex); boost::unique_lock<boost::mutex> lock(newTaskMutex);
++nThreadsServicingQueue; ++nThreadsServicingQueue;
stopRequested = false;
stopWhenEmpty = false;
// newTaskMutex is locked throughout this loop EXCEPT // newTaskMutex is locked throughout this loop EXCEPT
// when the thread is waiting or when the user's function // when the thread is waiting or when the user's function