Skip to content

Commit ed0223e

Browse files
committed
scheduler: Workaround negative nsecs bug in boost's wait_until
Some boost versions have a bug that can cause a time prior to system boot (or wake from sleep) to throw an exception instead of return timeout See boostorg/thread#308
1 parent 9828f9a commit ed0223e

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/scheduler.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,20 @@ void CScheduler::serviceQueue()
5656
// Explicitly use a template here to avoid hitting that overload.
5757
while (!shouldStop() && !taskQueue.empty()) {
5858
boost::chrono::system_clock::time_point timeToWaitFor = taskQueue.begin()->first;
59-
if (newTaskScheduled.wait_until<>(lock, timeToWaitFor) == boost::cv_status::timeout)
60-
break; // Exit loop after timeout, it means we reached the time of the event
59+
try {
60+
if (newTaskScheduled.wait_until<>(lock, timeToWaitFor) == boost::cv_status::timeout) {
61+
break; // Exit loop after timeout, it means we reached the time of the event
62+
}
63+
} catch (boost::thread_interrupted) {
64+
// We need to make sure we don't ignore this, or the thread won't end
65+
throw;
66+
} catch (...) {
67+
// Some boost versions have a bug that can cause a time prior to system boot (or wake from sleep) to throw an exception instead of return timeout
68+
// See https://github.com/boostorg/thread/issues/308
69+
// Check if the time has passed and, if so, break gracefully
70+
if (timeToWaitFor <= boost::chrono::system_clock::now()) break;
71+
throw;
72+
}
6173
}
6274
#endif
6375
// If there are multiple threads, the queue can empty while we're waiting (another

0 commit comments

Comments
 (0)