does usleep() sleep more than it's supposed to?

Carlo Florendo subscribermail@gmail.com
Mon Feb 26 07:57:00 GMT 2007


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.

I've attached a simple test case that let's usleep() sleep at
100000 microseconds at each call.

I've also included the output of cygcheck -svr.

The output of the attached code on my system is the following:

admin@host144 /cygdrive/e/midi
$ gcc time2.c

admin@host144 /cygdrive/e/midi
$ ./a.exe
Print elapsed time at every call to usleep()
Elapsed time (sec:microsec) 0:109000
Elapsed time (sec:microsec) 0:109000
Elapsed time (sec:microsec) 0:110000
Elapsed time (sec:microsec) 0:109000
Elapsed time (sec:microsec) 0:109000
Elapsed time (sec:microsec) 0:110000
Elapsed time (sec:microsec) 0:109000
Elapsed time (sec:microsec) 0:110000
Elapsed time (sec:microsec) 0:109000
Elapsed time (sec:microsec) 0:109000

Print elapsed after the loop()
Elapsed time (sec:microsec) 1:94000
                             ^^^^^^^
                          calling usleep() 10 times
                          made it sleep an additional
                          94000 microseconds.



Please note that I am aware of GetSystemTimeAdjustment()
and it seems not to have an effect on my observations.

Is the above the expected usleep() behaviour?  If not, how do we let 
usleep() sleep properly?


Thank you very much!

Best Regards,

Carlo



-- 
Carlo Florendo
Softare Engineer/Network Co-Administrator
Astra Philippines Inc.
UP-Ayala Technopark, Diliman 1101, Quezon City
Philippines
http://www.astra.ph

Member of the Astra Group of Companies
5-3-11 Sekido, Tama City
Tokyo 206-0011, Japan
http://www.astra.co.jp
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: cyg.out
URL: <http://cygwin.com/pipermail/cygwin/attachments/20070226/a7ec3ee7/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: time2.c
URL: <http://cygwin.com/pipermail/cygwin/attachments/20070226/a7ec3ee7/attachment.c>
-------------- next part --------------
--
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/


More information about the Cygwin mailing list