Re: [AD] proposal: al_sleep()

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


On Thu, 1 Jan 2004, Elias Pschernig wrote:

> On Mon, 2003-12-29 at 10:07, Eric Botcazou wrote:
> > > but since Allegro already has yield_timeslice () - which is rather
> > > useless in my opinion - shouldn't we provide an al_sleep(), with
> > > al_sleep(0) deprecating yield_timeslice()?
> >
> > Yes, this makes sense I think.
> >
>
> I just started implementing al_sleep, and noticed that yield_timeslice
> behaves quite differently under windows and unix compared to other
> platforms. BeOS and OSX sleep 30000 micro-seconds, QNX sleeps 10000
> micro-seconds. Windows sleeps 0 milliseconds (not at all), same as unix
> which calls sched_yield.

Yield_timeslice does this:

       On  systems  that  support  this, gives up the rest of the
       current scheduler timeslice. Also known as the "play  nice
       with multitasking" option.

On systems with direct support for such feature, it immediately gives up
its timeslice, on other systems it should sleep for the smallest possible
time (to force rescheduling).

> 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().

Have a nice day.

Stepan Roh




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