[Python-Dev] Stackless Design Q.

Christian Tismer tismer@tismer.com
Tue, 19 Feb 2002 20:15:31 +0100

Hi friends,

my tasklets are flying.

Now I am at the point where I'm worst suited for:
Design an interface.

First of all what it is:
We have a "tasklet", a tiny object around chains of frames,
with some additional structure that keeps C stack snippets.

Ignore the details, tasklets are simply the heart of Stackless'

The tstate maintains two lists of tasklets.
One is the list of all running (or better "runnable"?) tasklets.
These tasklets are not in "value state", they don't want to
transmit a value. They can be scheduled as you like it.

The other list keeps record of blocked tasklets. These are
tasklets which are in "value state", they are waiting to
do some transmission.

Whenever a tasklet calls an other tasklet's "transfer"
method for data transfer, the following happens:
- the other tasklet is checked to be in blocked state.
- the tasklet is removed from the runnable list,
- it is blocked
- data is transferred
- the other tasklet is unblocked
- the other tasklet is inserted into the runnables
- the other tasklet is run

The "transfer" word comes from Modula II. It implements
coroutine behavior.

Then, I have something like the ICON suspend, and I gave
it the name "suspend" for now, since yield is in use.
Suspend is a one-sided thing, and it is also needed
to initiate a blocked state at all.

Thre is a "client" variable that holds a reference
to the tasklet that called "transfer".

When suspend is called, then we have two cases:
1) There is another tasklet in the client variable.
    We take the client and call client.transfer(data)
2) There is no client set already.
    We go into blocked state and wait, until some
    tasklet transfers to us.

What suspend does is yielding (like in generators),
but also initial blocking, providing targets for
transfer to jump to.

What I'm missing is name and concept of an opposite
method: Finish the data transfer, but leave both
partners in runnable state.

Ok, here a summary of what I have.
Please tell me what you think, and what you'd like
to change.

stackless module:

     switch to the next task in the runnable list.

     call it with a function, and it generates a generator
     for tasklets.

ret = suspend(value)
    initiates data exchange, see above. The current tasklet
    gets blocked. If client is set already, a transfer is


def demo(n):
     print n

factory = taskoutlet(demo)

t = factory(42)   # this is now a tasklet with bound arguments.

tasklet methods:

     inserts t into the according tasklet ring at the "end".
     if t is in a ring already, it is removed first.
     The ring is either "runnables" or "blocked", depending
     on t's state.

     removes t from whatever ring it is in.

     inserts t into runnables and switches to it immediately.

ret = t.transfer(value)
     unblocks t, tansfers data, blocks myself.


Again, What is the name of this function/method, and
where does it belong?
- unblocks another tasklet
- transfers data
- does not block anything
- schedules the other tasklet

Or is this a bad design at all?
If so, please help me as well.

Thanks in advance - ciao - chris

p.s.: Not all of the above is implemented already.

Christian Tismer             :^)   <mailto:tismer@tismer.com>
Mission Impossible 5oftware  :     Have a break! Take a ride on Python's
Kaunstr. 26                  :    *Starship* http://starship.python.net/
14163 Berlin                 :     PGP key -> http://wwwkeys.pgp.net/
PGP Fingerprint       E182 71C7 1A9D 66E9 9D15  D3CC D4D7 93E2 1FAE F6DF
      where do you want to jump today?   http://www.stackless.com/