[Stackless] Algorithm for Stackless Scheduler

Jeff Senn senn at maya.com
Tue Nov 11 17:26:52 CET 2008


Here... I'll contribute a try-to-be-brief summary (to the best of my  
recollection):

There is a special: the "main" tasklet.
There is a doubly-linked (circular) list of "runnable" tasklets.
The head of the runnables is the "current" tasklet  (unless "main" is  
current...)

Calling tasklet.insert() inserts (or re-inserts) at the END of the  
runnables.
Calling tasklet.remove() removes from runnables.
Calling stackless.schedule() rotates the head of runnables to the NEXT  
one after current
   and switches to it.

Calling chan.receive/send() can remove the current tasklet from  
runnables
   if nothing is "waiting at the other end" (the NEXT tasklet in  
runnables
   is continued).

   OR (depending on the channel preference) continue in the caller
   (inserting the sender/receiver at the "other end" onto runnables)
   or rotate the head of runnables to the sender/receiver and pick up  
there.

"Preemptive" Scheduling:

t = stackless.run() pauses the "main" tasklet and begins running from  
runnables.

If the timeout argument is used, whatever tasklet is current after  
some number
of eval loops is paused and the "main" tasklet returned to. (A simple  
scheduler
at this point could call say "t.insert()" to rotate runnables and call  
stackless.run()
again causing "preemptive round robin" behavior.

Note that the scheduling order is not necessarily strictly a fair  
"round robin" --
since the head of the queue is "rotated" at some points, theoretically  
such a
scheduler could starve some tasklets under certain circumstances.



On Nov 11, 2008, at 9:44 AM, Andrew Francis wrote:

> Hi Folks:
>
> I understand that the Stackless documentation says that tasklets are  
> scheduled in a round-robin fashion. However I am interested in a  
> more detailed description of the scheduling algorithm. To keep thing  
> simple, a description of the scheduler in non-preemptive mode would  
> be nice. In particular, I am interested in how channel preferences  
> come into the picture. I know the code is out there, but I would  
> like to start with a high level description.
>
> Cheers,
> Andrew
>
>
>
>
> _______________________________________________
> Stackless mailing list
> Stackless at stackless.com
> http://www.stackless.com/mailman/listinfo/stackless
>





More information about the Stackless mailing list