Files
2025-10-25 03:02:53 +03:00

5.6 KiB
Raw Permalink Blame History

[thread.req.timing]

32 Concurrency support library [thread]

32.2 Requirements [thread.req]

32.2.4 Timing specifications [thread.req.timing]

1

#

Several functions described in this Clause take an argument to specify a timeout.

These timeouts are specified as either a duration or a time_point type as specified in [time].

2

#

Implementations necessarily have some delay in returning from a timeout.

Any overhead in interrupt response, function return, and scheduling induces a “quality of implementation” delay, expressed as duration Di.

Ideally, this delay would be zero.

Further, any contention for processor and memory resources induces a “quality of management” delay, expressed as durationDm.

The delay durations may vary from timeout to timeout, but in all cases shorter is better.

3

#

The functions whose names end in _for take an argument that specifies a duration.

These functions produce relative timeouts.

Implementations should use a steady clock to measure time for these functions.293

Given a duration argument Dt, the real-time duration of the timeout is Dt+Di+Dm.

4

#

The functions whose names end in _until take an argument that specifies a time point.

These functions produce absolute timeouts.

Implementations should use the clock specified in the time point to measure time for these functions.

Given a clock time point argument Ct, the clock time point of the return from timeout should be Ct+Di+Dm when the clock is not adjusted during the timeout.

If the clock is adjusted to the time Ca during the timeout, the behavior should be as follows:

  • (4.1)

    If Ca>Ct, the waiting function should wake as soon as possible, i.e., Ca+Di+Dm, since the timeout is already satisfied. This specification may result in the total duration of the wait decreasing when measured against a steady clock.

  • (4.2)

    If Ca≤Ct, the waiting function should not time out until Clock::now() returns a time Cn≥Ct, i.e., waking at Ct+Di+Dm. [Note 1: When the clock is adjusted backwards, this specification can result in the total duration of the wait increasing when measured against a steady clock. When the clock is adjusted forwards, this specification can result in the total duration of the wait decreasing when measured against a steady clock. — end note]

An implementation returns from such a timeout at any point from the time specified above to the time it would return from a steady-clock relative timeout on the difference between Ct and the time point of the call to the _until function.

Recommended practice: Implementations should decrease the duration of the wait when the clock is adjusted forwards.

5

#

[Note 2:

If the clock is not synchronized with a steady clock, e.g., a CPU time clock, these timeouts can fail to provide useful functionality.

— end note]

6

#

The resolution of timing provided by an implementation depends on both operating system and hardware.

The finest resolution provided by an implementation is called thenative resolution.

7

#

Implementation-provided clocks that are used for these functions meet theCpp17TrivialClock requirements ([time.clock.req]).

8

#

A function that takes an argument which specifies a timeout will throw if, during its execution, a clock, time point, or time duration throws an exception.

Such exceptions are referred to as timeout-related exceptions.

[Note 3:

Instantiations of clock, time point and duration types supplied by the implementation as specified in [time.clock] do not throw exceptions.

— end note]

293)293)

Implementations for which standard time units are meaningful will typically have a steady clock within their hardware implementation.