[SDL] SDL_Delay() granularity

Matthew Miller mattdm at mattdm.org
Thu Jul 11 06:09:01 PDT 2002

On Thu, Jul 11, 2002 at 05:21:04PM +1200, Gib Bogle wrote:
> Is SDL_Delay() on Linux limited to a granularity of 10 ms?  I could have
> sworn that previously I was able to ask for and get delays of less than
> 10 ms, but playing with testgl.c I observe that the delay is always 10,
> 20, ... ms.  Is my memory playing up again?

10ms is the minimum scheduler timeslice on x86 Linux. This means that if
your process gives up control -- or has it taken away by the OS -- it'll be
at least 10ms before you get it back. On Alpha Linux, it's around 1ms. This
actually may change on intel in the next kernel release, which'll make
things nice. <http://lwn.net/Articles/4228/>.

Anyway, the way to cope with this is to SDL_Delay(0) to release to the
scheduler periodically without specifically requesting a pause, and make
your loop timing independent of this delay. If you *don't* do this, the
scheduler will see your process as a CPU hog and and schedule you away
anyway, but at times when you weren't expecting it.

Matthew Miller           mattdm at mattdm.org        <http://www.mattdm.org/>
Boston University Linux      ------>                <http://linux.bu.edu/>

More information about the SDL mailing list