From 5b9d96912ddd9bfd05ea03994ae733a031cdcfcb Mon Sep 17 00:00:00 2001
From: Mike Crowe <mac@mcrowe.com>
Date: Mon, 22 Jun 2015 12:01:22 +0100
Subject: [PATCH] thread::try_join_until: Avoid busy wait if system clock
changes
If system clock changes by an amount larger than the outstanding duration
according to the supplied clock then the code loops around again but
continues to pass a time point based on the original value of the system
clock to the system_clock variant of try_join.
If we're going to recalculate the outstanding duration in the loop then it
is necessary to get the current time according to the system clock to use
with this duration.
Signed-off-by: Mike Crowe <mac@mcrowe.com>
---
include/boost/thread/detail/thread.hpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/boost/thread/detail/thread.hpp b/include/boost/thread/detail/thread.hpp
index b80eacf..727282b 100644
a
|
b
|
namespace boost
|
485 | 485 | bool try_join_until(const chrono::time_point<Clock, Duration>& t) |
486 | 486 | { |
487 | 487 | using namespace chrono; |
488 | | system_clock::time_point s_now = system_clock::now(); |
489 | 488 | bool joined= false; |
490 | 489 | do { |
| 490 | system_clock::time_point s_now = system_clock::now(); |
491 | 491 | typename Clock::duration d = ceil<nanoseconds>(t-Clock::now()); |
492 | 492 | if (d <= Clock::duration::zero()) return false; // in case the Clock::time_point t is already reached |
493 | 493 | joined = try_join_until(s_now + d); |