[Python-Dev] Re: [Stackless] comments on PEP 219

Christian Tismer tismer@tismer.com
Fri, 16 Mar 2001 11:37:30 +0100


This is going to be a hard task.
Well, let me give it a try...

Greg Ewing wrote:
> 
> > But most probably, it will run interpreters from time to time.
> > These can be told to take the scheduling role on.
> 
> You'll have to expand on that. My understanding is that
> all the uthreads would have to run in a single C-level
> interpreter invocation which can never be allowed to
> return. I don't see how different interpreters can be
> made to "take on" this role. If that were possible,
> there wouldn't be any problem in the first place.
> 
> > It does not matter on which interpreter level we are,
> > we just can't switch to frames of other levels. But
> > even leaving a frame chain, and re-entering later
> > with a different stack level is no problem.
> 
> You'll have to expand on that, too. Those two sentences
> sound contradictory to me.

Hmm. I can't see the contradiction yet. Let me try to explain,
maybe everything becomes obvious.

A microthread is a chain of frames.
All microthreads are sitting "below" a scheduler,
which ties them all together to a common root.
So this is a little like a tree.

There is a single interpreter who does the scheduling
and the processing.
At any time, there is
- either one thread running, or
- the scheduler itself.

As long as this interpreter is running, scheduling takes place.
But against your assumption, this interpreter can of course
return. He leaves the uthread tree structure intact and jumps
out of the scheduler, back to the calling C function.
This is doable.

But then, all the frames of the uthread tree are in a defined
state, none is currently being executed, so none is locked.
We can now use any other interpreter instance that is
created and use it to restart the scheduling process.

Maybe this clarifies it:
We cannot mix different interpreter levels *at the same time*.
It is not possible to schedule from a nested interpreter,
sincce that one needs to be unwound before.
But stopping the interpreter is a perfect unwind, and we
can start again from anywhere.
Therefore, a call-back driven UI should be no problem.

Thanks for the good question, I did never competely
think it through before.

ciao - chris

-- 
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/