SUMMARY: Need millisecond sleep() subroutine

From: Don Catey (catey@wren.geg.mot.com)
Date: Thu Aug 01 1996 - 11:12:45 CDT


Thanks to everyone that replied (far too many to list). I appreciate your
help.

The overwhelming vote is for usleep, which will allow sleeping in micro-
seconds. There were also suggestions for nanosleep, poll (NULL, 0, n)
and the following select routine from Gregory Bond:

struct tv stime = {0, 500000}; /* 500 ms */

select(0, 0, 0, 0, &stime);

And there was also this from Ernst-Gunar Ortlepp:
#include <sys/param.h>
#include <sys/types.h>
#include <sys/time.h>

void
u_sleep(value)
int value;
{
        fd_set *A=NULL,*B=NULL,*C=NULL;
        struct timeval tt;
 
        tt.tv_sec = 0;
        tt.tv_usec = value;
 
        select(0,A,B,C,&tt);
}

Then there is this from Trevor Paquette:
/* sleeps for the specified time. */

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

#define ITIMER_REAL 0

nap(seconds,micro_seconds)
long seconds, micro_seconds;
{
 int do_nothing();
 struct itimerval new_value, old_value;

 /* set time for timeout */
 new_value.it_value.tv_sec = seconds;
 new_value.it_value.tv_usec = micro_seconds;
 /* and don't reload it when it times out */
 new_value.it_interval.tv_sec = 0;
 new_value.it_interval.tv_usec = 0;

 /*catch the signal*/
 signal(SIGALRM,do_nothing);

 /* start the timer */
 setitimer(ITIMER_REAL,&new_value,&old_value);

 /* wait for the signal */
 pause();

 /*restore any old values */
 setitimer(ITIMER_REAL,&old_value,&new_value);
 return(1);
}

do_nothing ()
{
}

Original Message:

> Does anyone know of a C sleep subroutine that will give delays in
> milliseconds instead of seconds or any increment less than a second?

Best Regards!!!

--------------------------------------------------------------
Don Catey Internet: catey@wren.geg.mot.com
Systems Administrator Compuserve: 103533.2772@compuserve.com

--------Information Technology Solutions and Support----------

Motorola, Inc. Voice: 602/675-2608
Space & Systems Fax: 602/441-7138
    Technology Group
8201 East McDowell Road Any views, thoughts, or opinions
M/S H1192 expressed are my own, and are in
Scottsdale, AZ 85257 no way those of Motorola, Inc.
--------------------------------------------------------------



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:11:06 CDT