[SDL] How to get constant framerates without busywaits ...

David Olofson david.olofson at reologica.se
Thu Mar 14 12:10:02 PST 2002


On Thursday 14 March 2002 20:34, Kylotan wrote:
> From: David Olofson <david.olofson at reologica.se>
> Sent: Thursday, March 14, 2002 7:13 PM
>
> >BTW, sched_yield() is a pthreads calls. Don't know what it's called on
> >non-posix platforms, but I'd be surprized to see a multitasking OS
> > that doesn't have a corresponding call. (What it does is basically
> > "call"
>
> the
>
> >scheduler to see if any other thread has some work to do. If you're
> > the only runnable thread, the call just returns.)
>
> I think people use Sleep(0) on Win32 to achieve a similar effect.

Ah! Now that you say it... :-)

BTW, yes, I did discover that SDL_Delay() does *not* work this way - at 
least not on Linux. Maybe it does on Windows...?

	*looks at the source*

Looking at the source, it should, provided you're right about Sleep(0).

	*looks at the Linux version*

Well, there is some #ifdef'ed yield call in there, but if that isn't 
compiled in by default, it seems to me that SDL_Delay(0) will effectively 
do nothing - which is very different from yielding!

How about throwing in

	if(!ms)
	{
		pthread_yield();
		return;
	}

before the while loop, to make it behave like on Win32 - or do we still 
have Linux systems without pthreads (or rather, pthread_yield()) around?


//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