Re: [AD] proposal: al_sleep()

[ Thread Index | Date Index | More Archives ]

On Fri, 2 Jan 2004, Elias Pschernig wrote:

> On Fri, 2004-01-02 at 08:48, aj wrote:
> > >  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.
> >
> >
> > sleep(1)  on win32  tends to sleep approx 10 unless the  timeBeginPeriod(1)
> > is set.
> > so unless the user or allegro uses the  timeBeginPeriod(1)  the user is not
> > going to get 1ms sleep, but 10ms.
> > this will cause sluggish response.
> > on faster and ever faster CPU's, where we demand more processing, sleep
> > 10ms is a very long time.
> >
> > (use of timeBeginPeriod(1) also has some side effects, so if allegro is to
> > implement it, these side effects must be considered).
> >
> > yeild_timeslice()  is not supposed to be used to sleep your app...  its all
> > about allowing other apps to run if they want.
> > if your trying to sleep your app then use sleep(>0).
> > so i think yeild_timeslice() is still a very important function..    how
> > you call it  ie al_sleep(0) is still a good idea.
> >
> Ok, the question is - if I'm in a loop where I don't want to give up a
> timeslice - would I call yield_timeslice in it? Maybe Allegro was meant
> to be used with a non-preemptive OS, so yield_timeslice() would be
> important. But on the 2 OSes where yield_timeslices() currently is
> implemented as stated in the docs, there is preemptive multithreading.
> So if I want 100% CPU, I don't call yield_timeslice. If I have an idle
> loop, I call it, and want CPU to drop to 0.

In that case you are using it against the docs. yield_timeslice() simply
does what it should - it YIELDS TIMESLICE = your process/thread gives up
the rest of its timeslice and gives it to another one in ready-to-run
queue. If there is no such process/thread, your thread will run again.
The only way you can drop CPU usage is to sleep (= block somewhere) and
yield_timeslice() is not (and will not be) doing that.

By using yield_timeslice() you simply say: I have something to do, but it
is not that important, so I don't need to run right now.

> So my patch always improves things.

It's not improvment, it's replacing it with another function. al_sleep()
is good idea, but destroying yield_timeslice() is not.

Have a nice day.

Stepan Roh

Mail converted by MHonArc 2.6.19+