Date: Wed, 10 Jun 2026 08:41:42 -0700
On Wednesday, 10 June 2026 02:46:37 Pacific Daylight Time jim x via Std-
Discussion wrote:
> uint64_t timestamp() {
> auto now = std::chrono::steady_clock::now().time_since_epoch();
> return
> std::chrono::duration_cast<std::chrono::nanoseconds>(now).count();
> }
Despite the text not exactly saying so, I would expect this to be equivalent
to:
extern std::atomic<int64_t> steady_clock_value;
int64_t timestamp()
{ return steady_clock_value.load(std::memory_order_relaxed); }
And there's another thread somewhere that periodically executes:
steady_clock_value.fetch_add(1, std::memory_order_relaxed);
and nothing ever decrements this counter. With this, I think you can apply
regular happens-before relationships.
While this other thread *should* run with a period of 1 ns, it is not required
to do so. It's perfectly valid for the clock to batch updates in bigger
increments. This means any particular execution may fall below the update
granularity of the clock and thus two reads from this clock need not be
different.
Discussion wrote:
> uint64_t timestamp() {
> auto now = std::chrono::steady_clock::now().time_since_epoch();
> return
> std::chrono::duration_cast<std::chrono::nanoseconds>(now).count();
> }
Despite the text not exactly saying so, I would expect this to be equivalent
to:
extern std::atomic<int64_t> steady_clock_value;
int64_t timestamp()
{ return steady_clock_value.load(std::memory_order_relaxed); }
And there's another thread somewhere that periodically executes:
steady_clock_value.fetch_add(1, std::memory_order_relaxed);
and nothing ever decrements this counter. With this, I think you can apply
regular happens-before relationships.
While this other thread *should* run with a period of 1 ns, it is not required
to do so. It's perfectly valid for the clock to batch updates in bigger
increments. This means any particular execution may fall below the update
granularity of the clock and thus two reads from this clock need not be
different.
-- Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org Principal Engineer - Intel Data Center - Platform & Sys. Eng.
Received on 2026-06-10 15:41:54
