Re: [AD] proposal: al_sleep() |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On Fri, 2004-01-02 at 00:38, Stepan Roh wrote:
[..]
> > Therefore, I'd like to first apply the attached patch, which improves
> > the bahavior of yield_timeslice under Windows and Unix (and
> > yield_timeslice can't be deprecated by al_sleep anyway - since
> > apparently the amount of sleeping time needs to be significantly higher
> > than 0 under the 3 operating systems I mentioned at first above.)
> >
> > I have no idea what the advantage of sched_yield is - but at least for
> > me, it causes 100% CPU usage - so the patch removes support for it.
>
> Manpage of sched_yield:
>
> A process can relinquish the processor voluntarily without
> blocking by calling sched_yield. The process will then be
> moved to the end of the queue for its static priority and
> a new process gets to run.
>
> Note: If the current process is the only process in the
> highest priority list at that time, this process will con-
> tinue to run after a call to sched_yield.
>
> Using sched_yield (and yield_timeslice on *nix) will ALWAYS cause 100% CPU
> usage. It's not "sleep", but "give a chance for other processes - if other
> no process is found, let us play with whole processor".
>
> I don't see any reason why yield_timeslice() should be changed at all. It
> does what it should. I guess you are using it wrong, especially in
> something like al_sleep().
>
I'm not using it in al_sleep(). I wanted al_sleep to have a way to
work-around the always 100% CPU problem, in a platform independent way.
I believed I could just use al_sleep (1) to achieve this - with al_sleep
(0) having the behavior of the current yield_time_slice, al_sleep (x)
being a non-busy-waiting rest (). But when I read the source of
yield_time_slice, I saw that it waits up to 30 ms (BeOS and OSX) on
various platforms. Which is exactly what I wanted my al_sleep (1) todo -
give up the current time_slice in a way so idle programs use 0% CPU.
Which is not the same as sched_yield under linux. But which my patch
makes it. And I still haven't found any reason why I would want the
sched_yield behavior - it just causes the CPU to heat up for no reason
in idle Allegro programs.
--
Elias Pschernig <elias@xxxxxxxxxx>