Can Unix sleep in terms of mili/micro?

Michael Morrell morrell at hpcuhb.HP.COM
Thu Sep 13 07:56:23 AEST 1990


/comp.unix.internals/james at dlss2.UUCP (James Cummings)/5:11 am  Sep 11, 1990/
>>        Can Unix sleep in terms of mili or mirco second?

> sleep_less_than_sec(x)
> int x;
> {
>	int i;
> 
> 	for (i = 0;i <= x;i++)
> 		;
> }

>	I'd think that would give you approx. 25 clock cycles, dependent on
>the machine, the load on the machine, etc.
----------

This is not a very good idea.  Any decent optimizer will simply optimize away
your code loop and you won't get any delay (although if you declare "i" as
volatile, it shouldn't be removed, but it's still very dependent on the
machine and its current load).

  Michael



More information about the Comp.unix.internals mailing list