[Stackless] Algorithm for Stackless Scheduler
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
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
Calling tasklet.insert() inserts (or re-inserts) at the END of the
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
if nothing is "waiting at the other end" (the NEXT tasklet in
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
t = stackless.run() pauses the "main" tasklet and begins running from
If the timeout argument is used, whatever tasklet is current after
of eval loops is paused and the "main" tasklet returned to. (A simple
at this point could call say "t.insert()" to rotate runnables and call
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
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.
> Stackless mailing list
> Stackless at stackless.com
More information about the Stackless