On 07/11/16 17:08, Anthony Williams wrote:
> On 11/07/16 14:57, Nicol Bolas wrote:
>> On Monday, July 11, 2016 at 4:45:52 AM UTC-4, Anthony Williams wrote:
>> Agreed. I wouldn't want to lose high_resolution_clock, but it probably
>> ought to be steady. I don't think "async_advance" would be sufficient.
>>
>>
>> Why does it need to be "steady"?
>>
>> What HRC needs to do is continuously advance. But the advancing may not
>> be at an exact, constant rate, which is what "steady" requires. What HRC
>> shouldn't do is suddenly change due to outside stuff.
>>
>> The problem with `is_steady` is that it enforces a lot of stuff:
>>
>> 1: No sudden changes due to external factors.
>> 2: Always advances.
>> 3: Advances at a fixed rate, within its accuracy.
>>
>> If I recall correctly, the old Win32 QueryPerformanceCounter had issues
>> on some CPUs where the moment-to-moment frequency of its ticks would
>> vary. Over time it would average out, but while it might have clock-tick
>> precision, the frequency wasn't always correct. Would such a clock be
>> considered "steady"? No, because it violates #3: it does not advance at
>> a truly fixed rate.
>
> That depends on what you mean by "within its accuracy". There is no way
> to specify the "accuracy" of a clock.
>
> The standard says "the time between clock ticks is constant", which is a
> very high bar: are there any clocks on Earth for which that is truly the
> case?
I'd like to think the standard doesn't require the implementation to
contradict the laws of General Relativity - after all, time and space
depends on mass and speed of the system, which the standard does not
describe at all. :)
I think the assumption is that the implementation must have an internal
clock which represents the contiguous timeline from the perspective of
this system. That clock can be backed by the CPU clock or a separate
clock source - that is irrelevant, as long as the source is part of the
system. The clock source can be imperfect from the point of view of
another system, like a human observer, but for the purpose of the
implementation that error is non-existent.
is_steady should return true when the particular C++ clock advances
strictly at the same rate as that clock source (i.e. a steady clock
represents the described above timeline). Non-steady clocks may have
varying rate of advancement in comparison to the steady clock, for
example, in attempt to synchronize with an external clock
source/timeline, like an NTP server. For example, in a fast moving
system steady_clock would advance in the same rate from perspective of
this system and realtime_clock (assuming it represents time on Earth)
would advance at a faster rate (again, from perspective of this system).
In this view, a clock that stops running at a certain point (e.g. when
the machine goes to sleep) and starts running again at the same rate
(e.g. upon wakeup) can still be considered steady. If the time of
sleeping cannot be observed by the program then that time does not
exist, as far as the program is concerned. That, of course, may or may
not be a good thing, which depends on the intention of the programmer.
This is why synchronizing between multiple clocks can be useful, and is
one thing that the current standard is lacking.
In practice though, I think it is typical to assume that the steady
clock does not stop even if the machine goes to sleep, although some
time-related services can fail to function properly (like, a timeout for
a wait on a condition variable will not fire while the machine is
sleeping; but it will fire as soon as the machine wakes up). I guess
that property of the steady clock can be considered an implementation
detail, although it would be nice to have some certainty from the standard.