This is the mail archive of the
mailing list for the Cygwin project.
Re: Cygwin with clock_gettime and CLOCK_MONOTONIC - gives always 0
- From: Tobias Burnus <burnus at net-b dot de>
- To: cygwin at cygwin dot com, fortran at gcc dot gnu dot org
- Date: Thu, 11 Apr 2013 23:06:20 +0200
- Subject: Re: Cygwin with clock_gettime and CLOCK_MONOTONIC - gives always 0
- References: <5166A0B3 dot 70801 at net-b dot de> <5166BCA1 dot 5040204 at net-b dot de> <20130411134835 dot GD18333 at calimero dot vinschen dot de> <51670B6B dot 3000503 at net-b dot de> <20130411195200 dot GJ18333 at calimero dot vinschen dot de> <51671EAA dot 8030901 at net-b dot de>
b) Newlib is broken. For clock_gettime, CLOCK_MONOTONIC is not
implemented. But both CLOCK_MONOTONIC and even _POSIX_MONOTONIC_CLOCK
(with value 200112L) are defined. However, POSIX states: "If the
Monotonic Clock option is supported, all implementations shall support
a clock_id of CLOCK_MONOTONIC defined in <time.h>."
Sorry, I read this backward. CLOCK_MONOTONIC has to be in time.h
according to POSIX . However, whether the monotonic-clock option is
supported, is given by _POSIX_MONOTONIC_CLOCK of unistd.h. POSIX states :
- "If a symbolic constant is defined with the value -1, the option is
- "If a symbolic constant is defined with the value zero, all headers,
data types, and functions shall be present. The application can check at
runtime to see whether the option is supported."
- "If a symbolic constant is defined with a value greater than zero, the
option shall always be supported when the application is executed."
Just looking at newlib, the value should be "-1"; but a value of "0" is
probably fine as well. For Cygwin it could also be > 0.
As Corinna has written as follow up, the latter is actually the case:
Only RTEMS and Cygwin define it (with value > 0).
Regarding the zero value, the patch she mentions is: "times.cc
(hires_ns::nsecs): Take bool parameter. If set to true, don't use prime
value (== return system wide absolute value).",
Thanks for the patch!
For libgfortran, as action item one should at least check whether
_POSIX_MONOTONIC_CLOCK is defined as >= 0 before assuming that monotonic
clocks work. (With 0 (as with glibc/Linux) or with when not defined, it
might be still available but according to POSIX that's only checkable
via |sysconf(_SC_MONOTONIC_CLOCK|) at runtime.)
Problem reports: http://cygwin.com/problems.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple