Fake threads (was [Python-Dev] ActiveState & fork & Perl)

Ken Manheimer klm@digicool.com
Wed, 7 Jul 1999 14:00:56 -0400


Christian wrote:

> Really, no concern necessary. The state is not saved at all
> (despite one frame), it is just not dropped. :-)

I have to say, that's not completely reassuring.-)  While little or
nothing additional is created, stuff that normally would be quite
transient remains around.

> To shorten this: The whole story is nothing more than a tree,
> where exactly one leaf is active at any time, and its view
> of the call chain is always linear.

That's wonderful - i particularly like that multiple continuations from
the same frame only amount to a single retention of the stack for that
frame.  My concern is not alleviated, however.

My concern is the potential, but often-realized hairiness of computation
trees.  Eg, looped calls to a function amount to nodes with myriad
branches - one for each iteration - and each branch can be an arbitrary
computation.  If there were a continuation retained each time around the
loop, worse, somewhere down the call stack within the loop, you could
quickly amass a lot of stuff that would otherwise be reaped immediately.
So it seems like use of continuations *can* be surprisingly expensive,
with the expense commensurate with, and as hard (or easy) to predict as
the call dynamics of the call tree.

(Boy, i can see how continuations would be useful for backtracking-style
chess algorithms and such.  Of course, discretion about what parts of
the computation is retained at each branch would probably be an
important economy for large computations, while stashing the
continuation retains everything...)

(It's quite possible that i'm missing something - i hope i'm not being
thick headed.)

Note that i do not raise this to argue against continuations.  In fact,
they seem to me to be at least the right conceptual foundation for these
advanced control structures (i happen to "like" stream abstractions,
which i gather is what generators are).  It just seems like it may a
concern, something about which people experience with continuations
experience (eg, the scheme community) would have some lore - accumulated
wisdom...

ken
klm@digicool.com