setitimer with values less than 1000 microseconds

Ashif S. Harji
Mon Jun 26 13:24:00 GMT 2000

When I use setitimer with a value less than 1000 microseconds, no
sigalrms are generated.  Consider the following program:

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

int alarm( int sig ) {

int main() {
    itimerval it; 

    it.it_interval.tv_sec = 0;
    it.it_interval.tv_usec = 0; 

    it.it_value = (timeval){ 0,   // seconds
                             10 }; // microseconds
    signal( SIGALRM, (void (*)(int))alarm ); 

    setitimer( ITIMER_REAL, &it, (itimerval *)0 ); // set the alarm clock
to go off
    sigpause( 0 );  

} //

It simply hangs unless I use a timer value of 1000 microseconds or higher. 
When I run this program on a linux or sun sparc machine, it works fine. 
The difference seems to be that on these machines the timer value is
rounded up to the nearest resolution value.  However, with cygwin the
values are rounded down.  That is in the source code for setitimer in 

  elapse = itv.it_value.tv_sec * 1000 + itv.it_value.tv_usec / 1000; 
  if (elapse == 0) 
    return 0; 
  if (!(timer_active = SetTimer (gethwnd(), 1, elapse, NULL))) 
      __seterrno (); 
      return -1; 

elapse evaluates to 0 for values less than 1000 microseconds.  Thus, for
small time values, the timer is simply killed.  Is it possible to changes
this so that small time values are rounded up to the smallest resolution?

ashif harji

Want to unsubscribe from this list?
Send a message to

More information about the Cygwin mailing list