[SDL] Timer accuracy

David Olofson david.olofson at reologica.se
Mon Sep 16 01:21:01 PDT 2002

On Saturday 14 September 2002 04:23, Matt Greer wrote:
> On Friday 13 September 2002 11:48 am, Bill May wrote:
> > Most are accurate to 10 msec, at least on the linux
> > platforms.
> Why so fuzzy? On Linux, System.currentTimeMillis() in Java is accurate
> to 1ms. I assume they both access the same timer?

Yes, and no.

No hands-on Java experience, but I assume that System.currentTimeMillis() 
corresponds to SDL_GetTicks() - in which case both should have 1 ms 
accuracy on practically any platform. In fact, many platforms provide 
better accuracy than that on the system API level.

However, very few operating systems support timers that can wake up 
threads, send signals or something like that, with better than 10 ms 
accuracy. This is because of OS scheduler design, and on some platforms, 
there isn't much to do about it. The scheduler checks software timers at 
100 Hz, and that's it.

That said, Win32 has "multimedia timers" that support 1000 Hz scheduling, 
and Linux on virtually any PC or workstation (regardless of CPU) has the 
RTC, which can be programmed to generate IRQs up to 8192 Hz. 

Unfortunately, some Windows versions seem to have broken multimedia 
timers IIRC, and you have to be root to set the Linux RTC rate higher 
than 64 Hz. :-( Don't know much about other platforms.

//David Olofson --- Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
|      Multimedia Application Integration Architecture      |
| A Free/Open Source Plugin API for Professional Multimedia |
`----------------------------> http://www.linuxdj.com/maia -'
.- David Olofson -------------------------------------------.
| Audio Hacker - Open Source Advocate - Singer - Songwriter |
`-------------------------------------> http://olofson.net -'

More information about the SDL mailing list