gettime time travels after suspend

Philip Aston
Sat Apr 13 01:24:00 GMT 2002

I have a running process which prints out the result of gettimeofday()
at regular intervals. If I suspend and resume my machine then the
value returned by gettimeofday() is incorrect - it jumps several days
into the future. Doing the same with time() is fine.

I don't want to point fingers, but I suspect the following 1.3.10
 - Use QueryPerformance* functions for gettimeofday calls. (cgf)

Test case below.


- Phil

#include <time.h>
#include <sys/time.h>

int main() {
  struct timeval t;
  time_t t2;
  while (1) {
    gettimeofday(&t, 0);
    printf("gettimeofday() returns %ld %ld\n", t.tv_sec, t.tv_usec);
    printf("time() returns %ld\n", t2);


PASTON:philipa% uname -a
CYGWIN_NT-5.0 PASTON 1.3.10(0.51/3/2) 2002-02-25 11:14 i686 unknown
PASTON:philipa% ./gettimeofday-bug
gettimeofday() returns 1018681622 612224
time() returns 1018681623
gettimeofday() returns 1018681624 615154
time() returns 1018681625
gettimeofday() returns 1018681626 618384
time() returns 1018681627
<<< Suspend and resume machine >>>
gettimeofday() returns 1018932412 90805
time() returns 1018681632
gettimeofday() returns 1018932422 917318
time() returns 1018681642
gettimeofday() returns 1018932424 911611
time() returns 1018681644

Unsubscribe info:
Bug reporting:

More information about the Cygwin mailing list