Your program simply has a race, most likely due to the fact that 1 nanosecond is terribly short.
try_join_for try_join_until, , , :
bool try_join_for(const chrono::duration& rel_time)
{
return try_join_until(chrono::steady_clock::now() + rel_time);
}
bool try_join_until(const chrono::time_point& t)
{
system_clock::time_point s_now = system_clock::now();
bool joined= false;
do {
Clock::duration d = ceil<nanoseconds>(t-Clock::now());
if (d <= Clock::duration::zero())
return false;
joined = try_join_until(s_now + d);
} while (! joined);
return true;
}
, try_join_until , . , clock::now() , , . , 1 , .
, . - , CPU , . , .