The upcoming Y2038 catastrophe

Discussion of chess software programming and technical issues.

Moderator: Ras

bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Backward time steps

Post by bob »

mvk wrote:Here we have one caught in the wild:

bobo.c:

Code: Select all

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

int main(void)
{
        struct timeval tv1, tv2;   

        gettimeofday(&tv2, NULL);
        do {
                tv1 = tv2;

                gettimeofday(&tv2, NULL);
        } while((tv1.tv_sec < tv2.tv_sec) ||
                ((tv1.tv_sec == tv2.tv_sec) && (tv1.tv_usec <= tv2.tv_usec)));

        printf("tv1: %ld %d\n", tv1.tv_sec, tv1.tv_usec);
        printf("tv2: %ld %d\n", tv2.tv_sec, tv2.tv_usec);

        return 0;
}
Output:

Code: Select all

tv1: 1412665030 366901
tv2: 1412665029 267027
System log:

Code: Select all

7 Oct '14 8:57:09.268 AM ntpd[131]: ntpd: wake time set -1.099871 s
Nobody was near the computer when this happened, as I had just left a couple of minutes earlier. Last reboot was 3 days before.
Across a sleep/wake-up anything can happen. Just as it can across a reboot or anything else that violently stops the CPU so that ntpd can't continue to run and keep the clock current. Macs are absolutely notorious for doing that. I disabled it on my office machine since I use it to play on ICC automatically all the time. When it sleeps, it is unreachable from the network. Mine no longer sleeps.