Re: [AD] proposal: al_sleep()

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


On Fri, 2 Jan 2004, Elias Pschernig wrote:

> On Fri, 2004-01-02 at 11:36, Stepan Roh wrote:
> > I propose this:
> >
> > 1. make yield_timeslice() sleep as little as possible on platforms not
> > supporting sched_yield() or equivalent (everything except for Linux and
> > Windows).
> >
> > 2. make al_sleep(0) call yield_timeslice()
> >
>
> Yes, that makes sense. My only concern - will al_sleep(1) release CPU?
> This concern is raised by the sleeps of 30ms/10 ms inside the
> yield_timeslice versions of QNX/OSX/BeOS. So, it would look like this:
>
> al_sleep (1) -> usleep (1000);
> al_sleep (0) -> usleep (10000);

Then change yield_timeslice() to do usleep(1000) or less.

> That's exactly why I posted the yield_timeslice patch instead of the
> al_sleep patch. And by now I still fail to see when the current
> yield_timeslice in Windows/Linux is useful.
>
> > yield_timeslice() should improve responsivness of other programs not the
> > program calling it. It simply makes busy waits more polite allowing other
> > programs to take a chance. And busy waits are a must in current poll-like
> > input interface of Allegro.
>
> Yes, but these busy waits also work with my new yield_timeslice version.
> If I run e.g. exgui - it is as responsive as before, but uses 0% CPU.
> Clearly an improvement. And I fail to see where except in the Gui code
> there's any busy waits using yield_timeslice. User programs don't use
> yield_timeslice normally anyway - since it has no visible effect. The
> improved version OTOH gives incentive to be used, since nobody wants
> Allegro programs which use 100% CPU (even though they are not event
> driven - the sleeping yield_timeslice version seems to make it
> possible).

I don't see the reason why 100% CPU usage is bad.

> Just modifying yield_timeslice (and updating the docs) seems to be the
> most simple thing to do, with no need to introduce a new function.

I still don't think it is needed at all - just make al_sleep(0) (=
yield_timeslice()) sleep at most al_sleep(1) (or don't sleep at all and
use sched_yield() or eq.). Or leave yield_timeslice() alone and make
al_sleep(0) sleep the shortest possible time on given platform and let
user decide if it wants non-blocking or blocking CPU release. I think
that's the way:

1. leave yield_timeslice() as is
2. make al_sleep(0) sleep the shortest possible time on each platform (it
is sleep so it should sleep)
3. make al_sleep(x) sleep at least x miliseconds (or what units you have)

In this case al_sleep() should look like:

if (!x) { sys_sleep(SYS_MIN_SLEEP); } else { sys_sleep(sys_recalc(x)); }

Have a nice day.

Stepan Roh




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