[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Short sleeps.




Have any of you found a way to 'sleep' a process for less than 10ms?  I need
a process to sleep for about 1ms whilst allowing other processes to run
normally.

It's well known that 'usleep' will pretty much always return after >10ms
(and typically >20ms) no matter how short the period you ask for - even
if the CPU is completely idle.  That's a pain for games (where 16ms is a
lifetime).

This is evidently a well known problem because usleep basically just
calls nanosleep and 'man nanosleep' says:

  "The current implementation of nanosleep is  based  on  the
   normal  kernel  timer mechanism, which has a resolution of
   1/HZ s (i.e, 10 ms on Linux/i386 and 1 ms on Linux/Alpha).
   Therefore, nanosleep pauses always for at least the speci­
   fied time, however it can take up to  10  ms  longer  than
   specified  until  the  process becomes runnable again."

In a past project (don't ask!) I got fast sleep times by connecting
RxD to TxD on the serial port with a bent paperclip and writing a single
byte at 9600 baud...immediately reading it back again using 'select()'.
That would provide about a millisecond of delay without doing a busy/wait,
which is perfect!

I'm looking for something creative - but without the paperclip!

Any ideas?  (Yeah - I know "Buy an Alpha" :-)

----------------------------- Steve Baker -------------------------------
Mail : <sjbaker1@airmail.net>   WorkMail: <sjbaker@link.com>
URLs : http://www.sjbaker.org
       http://plib.sf.net http://tuxaqfh.sf.net http://tuxkart.sf.net
       http://prettypoly.sf.net http://freeglut.sf.net
       http://toobular.sf.net   http://lodestone.sf.net