Subject: setitimer() bug?
To: None <tech-kern@NetBSD.ORG>
From: msaitoh <msaitoh@spa.is.uec.ac.jp>
List: tech-kern
Date: 07/22/1998 02:08:38
 Hello.

 Please test followng program:

------------------------- nazo.c ---------------------------------
#include <sys/types.h>
#include <sys/time.h>
#include <sys/signal.h>
#include <stdio.h>

void
handler()
{
    static double prev = 0;
    struct timeval t;
    double now;

    gettimeofday(&t, 0);
    now = t.tv_sec + (double)t.tv_usec / (1000*1000);

    fprintf(stderr, "%d.%06d %lf\n", t.tv_sec, t.tv_usec, now - prev);
    prev = now;
}


void
main()
{
    int xxx = 0;
    struct itimerval it;
    signal(SIGALRM, handler);

    while (1) {
	if (xxx-- == 0) {
	    it.it_interval.tv_sec = 0;
	    it.it_interval.tv_usec = 100*1000;
	    it.it_value = it.it_interval;

#if defined(NeXT) || defined(sun)
            /* decrement 10msec */
	    it.it_value.tv_usec -= 10*1000;
#endif

	    setitimer(ITIMER_REAL, &it, 0);
	    fprintf(stderr, "SET\n");
	    xxx = 5;
	}
	select(0, NULL,NULL,NULL,NULL);
    }
}
------------------------- nazo.c ---------------------------------

 This program produces:

 > % ./a.out
 > SET
 > 865239161.391338 865239161.391338
 > 865239161.491316 0.099978
 > 865239161.591394 0.100078
 > 865239161.681519 0.090125     <---- 90ms!
 > 865239161.781474 0.099955
 > 865239161.881585 0.100111
 > SET
 > 865239161.981473 0.099888
 > 865239162.081518 0.100045
 > 865239162.181476 0.099958
 > 865239162.281517 0.100041
 > 865239162.381549 0.100032
 > 865239162.481516 0.099967
 > SET
 > 865239162.581527 0.100011
 > 865239162.671596 0.090069     <---- 90ms!
 > 865239162.771592 0.099996
 > 865239162.871670 0.100078
 > 865239162.971596 0.099926
 > 865239163.071596 0.100000


 This occurs many OS.

 Perhaps, this is a bug.

----------------------------------------------------------
		SAITOH Masanobu (msaitoh@spa.is.uec.ac.jp,
		                 msaitoh@netbsd.org)
		University of Electro-Communications