[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: firstname.lastname@example.org
- Subject: Short sleeps.
- From: Steve Baker <email@example.com>
- Date: Thu, 10 Jan 2002 18:59:22 -0600
- Delivered-To: firstname.lastname@example.org
- Delivered-To: mailing list email@example.com
- Delivery-Date: Thu, 10 Jan 2002 20:11:34 -0500
- Mailing-List: contact firstname.lastname@example.org; run by ezmlm
- Organization: Steve at Home
- Reply-To: email@example.com
- Sender: firstname.lastname@example.org
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
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
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 : <email@example.com> WorkMail: <firstname.lastname@example.org>
URLs : http://www.sjbaker.org
http://plib.sf.net http://tuxaqfh.sf.net http://tuxkart.sf.net