Re: [AD] rest and yield_timeslice

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Elias Pschernig wrote:
Well, not completely separate: If you do rest(x) with x other than 0,
you always yield.

Though there's an important difference. When you do rest(x) where x > 0, on platforms capable of course, you technically don't yield. Yielding implies stopping _only if_ there's something else on your priority level or higher that wants the timeslice. When you rest, you're actually lowering the process's priority level so that it's on par with the system idle process, if not lower (eg. completely inactive), until another process restores it. However, when you yield you keep your priority level the same.. you're merely put at the end of the queue so other processes of equal or higher priority can use the timeslice.

Now.. Windows seems to do something like this for Sleep:

set_process(lowest_priority);
do {
} while (wait_time > 0);
set_process(restore_priority);

of course, it just so happens that restoring priority automatically puts you at the end of the scheduler's queue.. so you get the effect, however ineffient, of a plain yield. However, I think this is completely inefficient for a game programming library as most games only want to give up the CPU if they really have to, so you would first check that you actually need to wait:

if(wait_time > 0)
{
   set_process(lowest_priority);
   do {
   } while (wait_time > 0);
   set_process(restore_priority);
}

Now, which do you think would be better for games, where you have situations like this:
while(playing) {
  do_frame();
  rest(expected_frame_time/*10ms for 100fps*/ - accum_frame_time);
}
If something like that hits <=0, you don't want to rest at all.

To bring a real-world analogy.. If you want to drive for 2 miles, you get in your car, start it up, drive 2 miles, shut it off. But if you want to drive for 0 miles, would you get in your car, start it up, then just shut it off? No, one would think you don't even bother going to the car at all. It's the same here, IMO.




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/