I've just done some experimenting on usleep in its Linux implementation
as it comes with a vanilla RedHat 5.0. It shows the following relation
between usleep argument and actual time waited (unloaded system, lapsed
times measured using pentium rdtsc method, system clock calibrated
against wall time as better than 10 ms/hour error, times written to
array (100 waits in a row), in effect no overhead) :

argument    time waited

<=10000     20 ms
  10001     30 ms
  20000     30 ms
  20001     40 ms

...and so on.

I would suspect usleep to encapsulate "the SIGALRM method of waiting"
(set an alarm, sending process a signal after a given time, wait for the
signal, handle it), at least it has a similar behaviour. I believe I've
read a warning somewhere that usleep may interfere with user signalling,
in effect one can not use a SIGALRM for some other purpose and at the
same time call usleep (can this be right ?). It seems that "the
select(3) method" behave similarly, though.

It seems that any waiting time specified is rounded up to something
being a multiple of 10 ms, and then a handling charge of further 10 ms
is added. One could guess that the kernel code handles alarms and other
such timing issues _after_ process administration, so that processes
being run as a consequence of any timing issue will first physically run
after the next 10 ms interrupt, hence the extra 10 ms (can't check, dont
have a kernel source right now).

Conclusion: the argument may say microseconds, but such waiting business
depends very much on implementation issues.

> ----------
> From:         Marin D[SMTP:[EMAIL PROTECTED]]
> Reply To:     Marin D
> Sent:         29. september 1998 09:59
> To:   SookYoung Kim
> Cc:   [EMAIL PROTECTED]
> Subject:      Re: Waiting for 125msecs.
> 
> 
> "man usleep"
> 
> 
> On Tue, 29 Sep 1998, SookYoung Kim wrote:
> 
> ->Hi, all
> ->I  need a function that waits for 125 msecs.
> -> As long as i know, sleep() function is only available for seconds.
> -> Is it right? If it is, I need to find another function or other
> things.
> ->Is there any function that wait for any msecs in LINUX?
> ->Please help me.
> ->If it's a stupid question, I'm sorry for that..
> 
> No. It's not.
> 

Reply via email to