Created on 2026-11-23.00:00:00 last changed 5 days ago
According to [time.clock.steady] p1:
Objects of class `steady_clock` represent clocks for which values of `time_point` never decrease as physical time advances and for which values of `time_point` advance at a steady rate relative to real time. That is, the clock may not be adjusted.
And [time.clock.req] p2 specifies:
`C1::now()`: Returns a `time_point` object representing the current point in time.
Furthermore, [intro.execution] p8 and [stmt.pre] p1 define the intra-thread evaluation order:
If A is sequenced before B (or, equivalently, B is sequenced after A), then the execution of A shall precede the execution of B.
Except as indicated, statements are executed in sequence ([intro.execution]).
Now consider the following example:
#include <thread>
#include <atomic>
#include <chrono>
#include <iostream>
int main() {
std::chrono::steady_clock::time_point c1, c2;
int read = 0;
std::atomic<int> val = 0;
std::thread t1([&]() {
val.store(1, std::memory_order::relaxed); // #0
c1 = std::chrono::steady_clock::now(); // #1
});
std::thread t2([&]() {
c2 = std::chrono::steady_clock::now(); // #2
read = val.load(std::memory_order::relaxed); // #3
});
t1.join();
t2.join();
if (c1 < c2) {
std::cout << read;
}
}
Suppose the execution yields c1 < c2. From the perspective of the abstract machine:
In thread `t1`, `#0` is sequenced before `#1`. By [intro.execution] p8, the evaluation of `#0` precedes `#1`. Since `#1` observes a point in physical time `c1`, `#0` is executed no later than physical time `c1`.
Similarly, in thread `t2`, `#2` is sequenced before `#3`. The evaluation of `#2` precedes `#3`. Since `#2` observes physical time `c2`, `#3` is executed no earlier than physical time `c2`.
Given c1 < c2, this establishes an apparent temporal order in physical time: #0 <= c1 < c2 <= #3.
However, from the standpoint of the memory model ([intro.multithread]):
There is no synchronizes-with relationship between `t1` and `t2` (relaxed operations do not synchronize).
Consequently, `#0` does not happen before `#3`.
Therefore, the memory model permits `#3` to observe `read == 0`.
This exposes a fundamental tension: Does the physical timeline observed via `now()` imply any execution in temporal order across threads within the abstract machine? Specifically: Does the observation c1 < c2 combined with `read == 0` mean that the abstract machine formally permits measuring "inter-thread store-to-load visibility latency"?
Currently, the standard treats real/physical time as an external concept that is observable via <chrono>, but fails to formally integrate it into the execution model. The standard currently makes physical time observable through `std::chrono::steady_clock::now()`, but fails to specify the semantics of such observations in conjunction with the control flow/memory order. It is completely vague whether sampling real time allows programmers to reason about the temporal ordering of evaluations across threads. Clarification is requested to bridge the gap between [time.clock] and the abstract machine's control flow.Suggested resolution:
I suggest explicitly specifying that the value returned by `now()` does not participate in any relationships implied by control flow, nor can it be used to deduce any partial ordering in physical time regarding the execution of surrounding evaluations.| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2026-11-23 00:00:00 | admin | create | |