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

Stephen Anthony stephena at roadrunner.nf.net
Sun Mar 17 15:04:01 PST 2002


On March 17, 2002 07:04 pm, you wrote:

> Why don't you want a busy wait? Why is everybody concerned with their
> CPU usage while running games?
>
> I don't think it is possible to get constant framerates without
> busywaits. If you try any other method you are blocking on some
> operating system controlled event.  When you do that you are leaving it
> up to the operating system to wake your thread again. Even a sleep for
> 2ms call is not gauranteed to return in 2ms, all it gaurantess is that
> it will be at least 2ms before it returns. You need a real time
> operating system to get gaurantees on how long your thread will sleep,
> thats why real time operating systems exist.

Well, there are a few reasons.  One is that this is an emulator that is 
extremely low powered.  Why use up the entire CPU when less than 1% would 
have been enough, even on a Pentium 100?

Also, what if it is ported to some portable device or something?  More 
CPU usage means more power consumption.  Actually, this is also related 
to current CPU's.  More processing translates to more heat being 
generated.

I guess the main reason is that I learned in CS that busywaits are 
sloppy.  They are, by definition, a waste of processor time.  Besides, 
I've seen other emulators that do it, so I know it can be done.  Problem 
is that by examining their code, I can't figure out how they did it :(  
Thats why I was looking for a general algorithm, maybe something that 
could help me understand how other people did it.

Its a matter of pride I guess.  The non busy-wait version would be much 
more 'elegant'.   It may not be required, but it would be icing on the 
cake.  I come from an Amiga background, where you had to conserve every 
resource you had.  I can't break free from that mentality, and honestly, 
I'm not sure that I want to :)

Steve




More information about the SDL mailing list