Re: [AD] WIP 4.1.15 and CVS freeze

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


Elias Pschernig wrote:
The attached patch is the same as the last, but I added in the
YIELD_TIME constant, adjusted the GUI and examples to use it, and
deprecated yield_timeslice.

I only looked through the patch without applying/testing it, but I think I spotted a couple problems. One:

        time = clock() + MIN(time * CLOCKS_PER_SEC / 1000, 2);
        do {
 +         system_driver->yield_timeslice();
        } while (clock() < (clock_t)time);

This will cause problems. Remember, clock() runs on the process's time, so if yield_timeslice succeeds in actually yielding, the clock time will be thrown off. Unfortunately, there's not much you can do other than return it to being a busy-wait loop until we implement a proper, OS-independant time counter.

Also, I just noticed the way you're yielding with rest(YIELD_TIME) is wrong. YIELD_TIME is defined to be 10 or 30 on some platforms, however, this is the /approximate/ time of the timeslice. It could end up returning a millisecond or two before this, in which case the wait time would be doubled since it would wait again, wouldn't it? And again, yielding implies stopping *only if* something else wants the CPU, it's not a forced thing. I think IDLE_TIME would be a better name for that define. And if you're going for dropping CPU usage, shouldn't rest(1) be sufficient on platforms that have a proper system sleep method? When we were talking about timeslices being 10ms in Windows and Linux, and 30ms in some other place, that's the approximate time it would take for the scheduler to get back to us after something else uses the CPU. Getting rescheduled and giving the CPU to the idle process (via rest(1)) should be sufficient to sleep the program for the entire timeslice, however long that may be. The only time rest(1) wouldn't work is if the system's sleep method would busy-wait on small numbers, which AFAIK only happens with nanosleep in real-time priority (and even there it only requires something greater than 2).

- Kitty Cat




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