Delay for a fraction of a second in C

Gordon Cross crossgl at ingr.UUCP
Wed Nov 9 05:23:31 AEST 1988


In article <26678 at ucbvax.BERKELEY.EDU>, jas at ernie.Berkeley.EDU (Jim Shankland) writes:
> 
> Never trust statements about the UNIX kernel from people who can't even
> spell the word.

Every so often this sort of thing pops up:  people abusing other people about
spelling errors.  This often (once started) gets out of hand as everyone
begins "flaming" other's spelling and/or punctuation errors swamping the net
with meaningless dribble.  So please if you wish to correct someone on a
spelling error, how about e-mail...

Now down to business...
In a previous article I wrote the following in response to a question regarding
how to sleep for a period of time less than one second in C:
>
> You are not going to be able to do this without coding up some kind of
> "delay loop" yourself.  Of course that solution is definitely NOT portable in
> any way since the loop would have to be fine tuned to your machines execution
> speed.  Remember that in the UNIX kernel, scheduled wakeups occur at fixed
> one second intervals.  Thus, unless you are using a non standard kernel,
> sleeps of only whole numbers of seconds are possible!

I have of course been catching some heat (from the flames :-)) regarding this
response.  And I must say it is well deserved!  In my attempt to keep the
answer as short as possible, I oversimplified the problem.  I also neglected
to mention that I would not actually RECOMMEND a "delay loop" since other
approaches (ie. NOT requiring sleeps of less than one second) are almost always
available.  Several responses to this question mentioned other methods whereby
this could be accomplished.  Each of these solutions rely on mechanisms (such
as BSD's sockets) not available on all UNIX implementations.  I was just
attempting to come up with a method that would be workable (if you absolutly
just HAD to have sub-second waits) on any implementation.  Sorry about the
confusion!


Gordon Cross
Intergraph Corp.  Huntsville, AL



More information about the Comp.lang.c mailing list