Re: [AD] proposal: al_sleep() |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
At 03:43 PM 2/01/2004 +0100, you wrote:
On Fri, 2004-01-02 at 15:20, aj wrote:
> >
> >Yes, so it would make sense for yield_timeslice to release CPU under
> >windows and linux - even though it means, a complete timeslice is given
> >up. All the patch does is replace Sleep(0) with Sleep(1) - and it
> >achieves just that - CPU drops from 100% to 0%. If I'm in a loop where I
> >need all the CPU power, I wouldn't call yield_timeslice - therefore the
> >10 ms I effectively lose don't matter. If I'm in an idle loop, and call
> >yield_timeslice, I don't want the CPU to run with 100% - therefore
> >giving up the timeslice with Sleep(1) makes more sense than keeping to
> >run with 100% CPU with Sleep(0).
>
>
> is sleep(1) really 1 ms ? on which system ?
> sleep(1) can actually be more harmful than yield, due to thrashing.
>
No, sleep(1) (small s) is 1 whole second.
>
> if you know how much sleep you need then call sleep(>0) dont go trying to
> change the meaning of yield.
>
I just want 0% CPU when idle and all the CPU when not idle. For example
some code of a, let's say, platformer game:
while (1)
{
while (game_frames < frames_ticker)
{
do_logic ();
}
if (rendered_frames < game_frames)
{
do_rendering ();
}
else
{
yield_timeslice ();
}
}
When I had this on my old pentoim 200 MHz, it rarly got to call
yield_timeslice - and instead used 100% of CPU to update and display the
game. Now, I have a processor which can run the same game 10 times at
once. So it should use only 10% CPU.
Instead, what happens is, yield_timeslice () is called millions of times
heating up the CPU for no reason.
yes i see the problem.
but the problem is you have implemented the wrong function.
yeild does exactly what it was designed for, and what millions of other
programmers know it for.
you should estimate the time to the next logic loop and sleep for that
amount of time.
that would work on the fast PC and the slow PC.
> >And in Linux, my experience is that releasing CPU improves
> >responsiveness of my programs compared to running on 100% CPU. (I can't
> >explain why this would be the case though. Probably the linux scheduler
> >penalties apps being 100% busy, and the sched_yield doesn't change
> >anything in that.)
>
>
>
> which linux scheduler ? i dont know that much about the world of linux,
> but aren't there different schedulers out there ?
> also, how can you say you get more responsiveness when its using less
CPU..
> thats a complete contradiction.
>
Yes, ideally, it would be so simple. But don't forget, there's more than
one thread running in Allegro, and there's a lot of background processes
running all the time in linux. I only noticed this behavior after some
recent kernel updates - so yes, it is caused by a change in the linux
scheduler. And I can't really explain it as well.
given that you can not explain it, and the linux "platform" is such a
moving target, i think it best that you implement the correct algorithm.
that is to use Sleep(>0 ) where appropriate. and if you dont seem to see
how yield is important or useful; then just pretend it doesn't exist and
dont use it.. but PLEASE do not go changing its meaning.