Stackless/microthreads merge news

Christian Tismer tismer at tismer.com
Mon Mar 13 08:02:50 EST 2000


Konrad Hinsen wrote:
> 
> wware at world.std.com (Will Ware) writes:
> 
> > Chris Tismer and I expect to release microthreads running on
> > Stackless Python very soon. At this point things appear stable
> > enough that we can release a user's manual, available at
> > http://world.std.com/~wware/utdoc.html
> 
> Looks great! One question: are there any provisions to use
> microthreads in C extension modules? If yes, is the Python interpreter
> (the modified one) thread-safe for microthreads, or is there still
> something like the global interpreter lock? Getting rid of that would
> be reason enought to switch to microthreads for me.

Will's answer is valid. Just a few details here:
The Python interpreter is thread-safe for microthreads.
Even more, it is possible to run micro-threads in every
real thread. For a real thread, microthreads are just
Python code. Every thread state has its own microthread
handler.

But there are new, different restrictions. Uthreads cannot
switch frames across different interpreter recursions.
By default, every recursion of the Python machine locks
uthreads. Python code is used to unlock uthreads, by installing
an interrupt handler. The python machine interrupts itself
after a couple of ticks and does a task switch.

If you want to play this game, your C code must become a
switchable part of this system. Uthreads will always block
while the C code is executing. As Will said, you can split
your C code into a series of functions which can be scheduled
by interrupting the running Python frame.

If you can manage to keep all your state in sructures that
can be held in a frame, then you can use deep recursion in
your C code as well. But you have to express your recursion
by creating frames. This is what I call a stackless C extension.

cheers - chris

-- 
Christian Tismer             :^)   <mailto:tismer at appliedbiometrics.com>
Applied Biometrics GmbH      :     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
     we're tired of banana software - shipped green, ripens at home




More information about the Python-list mailing list