Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!apollo!vs_subbu From: vs_subbu@apollo.HP.COM (V. S. Subrahmanyam) Newsgroups: comp.unix.internals Subject: Re: Can Unix sleep in terms of mili/micro? Summary: Use blocking i/o on an ioctl'ed tty line. Message-ID: <4ccc35b4.20b6d@apollo.HP.COM> Date: 14 Sep 90 06:11:00 GMT References: <24437@adm.BRL.MIL> <37960001@hpcuhb.HP.COM> Sender: root@apollo.HP.COM Reply-To: vs_subbu@apollo.HP.COM (V. S. Subrahmanyam) Organization: Hewlett-Packard Company, Apollo Division; Chelmsford, MA Lines: 28 In article <37960001@hpcuhb.HP.COM> morrell@hpcuhb.HP.COM (Michael Morrell) writes: >/comp.unix.internals/james@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.