Can Unix sleep in terms of mili/micro?

V. S. Subrahmanyam vs_subbu at apollo.HP.COM
Fri Sep 14 16:11:00 AEST 1990


In article <37960001 at hpcuhb.HP.COM> morrell at hpcuhb.HP.COM (Michael Morrell) writes:
>/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;
>> }
>----------
>
>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

You can try using "blocking I/O" :

	1. Select a tty line that will not be used by any other person.
	2. Open the tty line for read
	3. ioctl that tty line , with vtime field in the c_cc array to
	the desired sleeping period.
	4. Read the fd associated with the tty line. Since nobody is
	writing any data to that fd, and since we are using blocking I/O,
	the read call will block for the duration specified in the
	vtime field.

Subbu.



More information about the Comp.unix.internals mailing list