Section: 30 [time] Status: Resolved Submitter: Christopher Kohlhoff, Jeff Garland Opened: 2008-02-03 Last modified: 2016-01-28
Priority: Not Prioritized
View all other issues in [time].
View all issues with Resolved status.
Discussion:
The draft C++0x thread library requires that the time points of type
system_time
and returned by get_system_time()
represent Coordinated
Universal Time (UTC) (section [datetime.system]). This can lead to
surprising behavior when a library user performs a duration-based wait,
such as condition_variable::timed_wait()
. A complete explanation of the
problem may be found in the
Rationale for the Monotonic Clock
section in POSIX, but in summary:
condition_variable::timed_wait()
(and its POSIX
equivalent, pthread_cond_timedwait()
) are specified using absolute times
to address the problem of spurious wakeups.
condition_variable::timed_wait()
that behave as if by calling the
corresponding absolute time overload with a time point value of
get_system_time() + rel_time
.
POSIX solves the problem by introducing a new monotonic clock, which is
unaffected by changes to the system time. When a condition variable is
initialized, the user may specify whether the monotonic clock is to be
used. (It is worth noting that on POSIX systems it is not possible to
use condition_variable::native_handle()
to access this facility, since
the desired clock type must be specified during construction of the
condition variable object.)
In the context of the C++0x thread library, there are added dimensions to the problem due to the need to support platforms other than POSIX:
One possible minimal solution:
system_time
and get_system_time()
implementation-defined (i.e standard library implementors may choose the
appropriate underlying clock based on the capabilities of the target
platform).
system_time::seconds_since_epoch()
.
explicit system_time(time_t secs, nanoseconds ns
= 0)
to explicit system_time(nanoseconds ns)
.
Proposed resolution:
Rationale:
Addressed by N2661: A Foundation to Sleep On.