Problem with usleep's precision.

qrw@bell.qrwsoftware.com qrw@bell.qrwsoftware.com
Tue Apr 15 18:56:00 GMT 2003


Ulrich Prakash Wrote:

Hi All,

I want to sleep my program for around 20 milliseconds period.
But usleep doesn't work correctly...

man page tells that usleep wud sleep for the microseconds time,but
when i gave usleep(1),it actually sleeps for 12000-14000
microseconds..

When i gave usleep(20000),it sleeps for 27000-29000microseconds
instead of 20,000...

I also tried using nanosleep,but nanosleep for 1 nanoseconds also
sleep for 12000-14000 microseconds.


I'm not sure, but I don't think there is a way to get precise times with
sleep because it just depends upon when the scheduler next runs and setsrunning again.

-Scott



More information about the Gcc-help mailing list