Cygwin with clock_gettime and CLOCK_MONOTONIC - gives always 0

Tobias Burnus burnus@net-b.de
Thu Apr 11 21:19:00 GMT 2013


Tobias Burnus:
> 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 [1]. However, whether the monotonic-clock option is 
supported, is given by _POSIX_MONOTONIC_CLOCK of unistd.h. POSIX states [2]:

- "If a symbolic constant is defined with the value -1, the option is 
not supported."
- "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).", 
http://cygwin.com/cgi-bin/cvsweb.cgi/src/winsup/cygwin/times.cc.diff?r1=1.117&r2=1.118&cvsroot=src&f=h

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.)

Tobias

[1] http://pubs.opengroup.org/onlinepubs/009695399/basedefs/time.h.html
[2] http://pubs.opengroup.org/onlinepubs/009695399/basedefs/unistd.h.html

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list