[Stackless] What to do with microthreads?

Christian Tismer tismer at tismer.com
Thu Feb 13 04:15:09 CET 2003

Xiang Zhang wrote:
> I think many newcomers to Stackless have the same question. I was 
> attracted to Stackless because of microthreads. Now how do we go about 
> doing business without it? Is there anyone in the Stackless community 
> working on a module to fill the shoes of microthreads?

A microthread module based upon tasklets and channels
is rather easy to build. I actually did one for CCPgames.
A microthread /is/ basically a tasklet.

The major difference is that 2.0 cannot easly support
pre-emptive scheduling. It is possible, but with huge
effort. I will explain this in depth in the upcoming

Short answer: Stackless 1.0 could not switch in many
contexts. This was fine for microthreads, they switched
only in safe contexts.
2.0 is too powerful, it can switch at any time. This is
ok for explicit task switches, but doing it automatically
gives a lot of problems: ou are switching in the context
of an extension that doesn't expect it, and you crash.

Unfortunately, it is not trivial to figure out whether
you are in an extension.

> Also will Stackless 3.0 solve this problem? It is mentioned somewhere 
> that it might have a fix for this, yet I don't know when 3.0 will be 
> available.

It will. 1.0 used a simple criterion: Automagic switching is
only allowed in the toplevel interpreter, unless you explicitly
enable it. 1.0 could identify a toplevel interpreter, since
it avoided recursive calls 80 percent of the time.
2.0 cannot easily do this. 3.0 gets these 80% back, where automatic
switching is ok, and by default disables it when a real C stack
has to be moved. The user can control this, but I again have
a good default behavior.

ciao - chris

Christian Tismer             :^)   <mailto:tismer at tismer.com>
Mission Impossible 5oftware  :     Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a     :    *Starship* http://starship.python.net/
14109 Berlin                 :     PGP key -> http://wwwkeys.pgp.net/
work +49 30 89 09 53 34  home +49 30 802 86 56  pager +49 173 24 18 776
PGP 0x57F3BF04       9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
      whom do you want to sponsor today?   http://www.stackless.com/

Stackless mailing list
Stackless at www.tismer.com

More information about the Stackless mailing list