From cygwin Mon Feb 26 17:37:14 2007 From: Christopher Layne Date: Mon, 26 Feb 2007 17:37:14 +0000 To: cygwin Subject: Re: does usleep() sleep more than it's supposed to? Message-Id: <20070226173714.GB22638 () ns1 ! anodized ! com> X-MARC-Message: https://marc.info/?l=cygwin&m=117251145607990 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/