From 5b9d96912ddd9bfd05ea03994ae733a031cdcfcb Mon Sep 17 00:00:00 2001 From: Mike Crowe 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 --- 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/include/boost/thread/detail/thread.hpp +++ b/include/boost/thread/detail/thread.hpp @@ -485,9 +485,9 @@ namespace boost bool try_join_until(const chrono::time_point& t) { using namespace chrono; - system_clock::time_point s_now = system_clock::now(); bool joined= false; do { + system_clock::time_point s_now = system_clock::now(); typename Clock::duration d = ceil(t-Clock::now()); if (d <= Clock::duration::zero()) return false; // in case the Clock::time_point t is already reached joined = try_join_until(s_now + d); -- 2.1.4