[alt.sources] "usleep" C routine for HP's

rosa@maui.cs.ucla.edu (04/28/89)

I have a C program with real time restrictions that uses the "usleep"
routine provided in the SUN's C library ("usleep" gives precision of
micro-seconds). In the HP's, there is not this routine. 
Does anybody know about any "nap" or "usleep" routine that would 
work in a HP machine with a precision of tenths-of-a-second at least?
The operating system is BSD4.3. 

Thanks in advance,

	--Berthier

stroyan@hpfcdc.HP.COM (Mike Stroyan) (05/01/89)

> Does anybody know about any "nap" or "usleep" routine that would 
> work in a HP machine with a precision of tenths-of-a-second at least?
> The operating system is BSD4.3. 

Use a "select" call timeout with 0 file descriptors.

Mike Stroyan, stroyan@hpstryn

burdick@hpindda.HP.COM (Matt Burdick) (05/02/89)

> Does anybody know about any "nap" or "usleep" routine that would 
> work in a HP machine with a precision of tenths-of-a-second at least?
> The operating system is BSD4.3. 

Try this:

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

usleep(usecs)
        u_long usecs;
{
        struct timeval tv;

        tv.tv_sec = usecs / 1000000L;
        tv.tv_usec = usecs % 1000000L;
        (void)select(0, 0, 0, 0, &tv);
}

------------------------------------

By the way, this was not written by me, I just grabbed it from another HP
machine.

-- 
Matt Burdick			| Hewlett-Packard
burdick%hpda@hplabs.hp.com	| Technical Communications Lab