This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: does usleep() sleep more than it's supposed to?
- From: Christopher Layne <clayne at anodized dot com>
- To: cygwin at cygwin dot com
- Date: Mon, 26 Feb 2007 09:37:14 -0800
- Subject: Re: does usleep() sleep more than it's supposed to?
- References: <45E292D6.30906@gmail.com>
On Mon, Feb 26, 2007 at 03:57:10PM +0800, Carlo Florendo wrote:
> Good Day,
>
> I'm writing an application that requires time precisions up to the
> microsecond level. However, I put a hard-coded adjustment of
> 9000 microseconds since usleep() seems to sleep on the average of
> 9000 microseconds more than it's supposed to, at least on my
> system. I could work with up to 2000 microseconds for
> function overhead but 9000 microseconds seems to be too long.
Without using POSIX Realtime extensions, you will *never* attain
consistent granularity at the microsecond level with any sleep()
function.
Think about it - on a preemptive multiprocess OS - the minimum
intervals the OS uses for handing out timeslices to all processes
contained within the current environment (and also the associated
forced sleeping of processes who have used too many of their
timeslices within a given interval) will always limit your
granularity.
-cl
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/