liveBook · Manning

Steady clock

As explained in C++ Concurrency in Action, Second Edition

A steady clock is a clock whose measured time never decreases and advances at a steady rate, making it suitable for measuring elapsed time.

A steady clock ticks at a uniform rate and cannot be adjusted. Its `is_steady` member is true; unlike `system_clock`, its `now()` value will not move backward because of clock adjustment. section 4.3.1

Use a steady clock for elapsed-time measurements and timeouts: a system-clock adjustment does not change the elapsed duration. A wait can still take longer than requested because of scheduling and clock precision. section 4.3.1 section 4.3.2

std::future<int> f=std::async(some_task);
if(f.wait_for(std::chrono::milliseconds(35))==std::future_status::ready)
    do_something_with(f.get());

A 35-millisecond future wait illustrates duration-based waiting measured with a steady clock. section 4.3.2

How C++ Concurrency in Action, Second Edition covers it

How deep it goes
Defines steadiness as a uniform, non-adjustable tick rate, identifies `is_steady`, and contrasts adjustable `system_clock`.
Examples
Uses a 35-millisecond future wait to show elapsed-time measurement despite system-clock adjustment.
What you can do after
Evaluate clock suitability for elapsed-time and timeout measurements by checking whether it is steady.
How it connects
Connects clock properties to durations and future waits, contrasting steady clocks with `system_clock`.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of C++ Concurrency in Action, Second Edition. The section links point to the parts of the book it draws on.