[SDL] Why not nanosleep()?

Mattias Engdegård f91-men at nada.kth.se
Mon Apr 3 08:47:59 PDT 2000

>Ups, timed the wrong one... usleep was the one that took 2 seconds and
>select was taking about 1 sec. Well, the 1000x1ms still takes 10 secs
>with select here but at least it works perfectly with a resolution of
>more than 10ms whereof usleep even fails on such a high granularity.

On Linux, select() and usleep() have a 10ms granularity, but usleep
often overshoots by up to 10ms since it has to sleep at least the
asked amount, not less. If you usleep() near the end of a tick, the delay
will be closer to what you asked for, but I presume your test program
did it just after the beginning of a tick.

(Except on Alpha, where a tick = 1/1024 s.)

I don't think SDL_Delay should busy-wait (often you delay to let other
threads run), so nanosleep() is out. We could provide a SDL_BusyWait(),
but the implementation is so trivial there's little point.

More information about the SDL mailing list