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 22:35:54 +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>
Corinna Vinschen wrote:
On Apr 11 21:13, Tobias Burnus wrote:
Where is actually the source code of the clock_gettime, which Cygwin
uses? I thought that it was newlib. But looking at
the code should return -1 for "clock_gettime (CLOCK_MONOTONIC" as
CLOCK_MONOTONIC (= 4) is not handled, only CLOCK_REALTIME (= 1,
according to src/newlib/libc/include/time.h).
However, as both you and Angelo get a zero return value, I must look
at the wrong file.
Yes, for Cygwin it's
Well, it's "times.cc" not "timer.cc". I think the problem with Cygwin
was a red herring. But there are a bunch of problems:
a) Angelo's code to initialize the random seed assumes that Fortran's
"system_clock" and the "clock_gettime(CLOCK_MONOTONIC" it calls give a
result where 0 is the beginning of the epoch (like on Linux/glibc) or
the system start up (as Windows' GetTickCount/GetTickCount64). However,
QueryPerformanceCounter (probably intrinsically, but at least as used by
Cygwin) returns some time based on the startup time - and as the
frequency seems to be slow such that the result is 0 or (nearly) the
same number for the startup. Thus, the random_seed initialization
doesn't work as expected on Cygwin/Windows.
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>."
* Newlib should be fixed to not define CLOCK_MONOTONIC and
_POSIX_MONOTONIC_CLOCK - or it should implement it, otherwise it doesn't
* Angelo shouldn't use system_clock to set the random seed.
* libgfortran should fall back to gf_gettime (= gettimeofday or
clock_gettime CLOCK_REALTIME or time) if clock_gettime returns nonzero
to work around the broken netlib (and possibly other implementations of
* gfortran's example for random_see should be change to not use
system_clock for the random seed.
Sorry for misinterpreting the results of Cygwin. And thanks for the
reply and testing.
Problem reports: http://cygwin.com/problems.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple