Concurrency support?
John Cowan
cowan at ccil.org
Mon Jun 26 07:41:35 PDT 2006
Brendan Eich scripsit:
> So far, the bugs or limitations combined with the promise of call/cc
> generality seem to me to indicate overkill, or overreach. If anyone
> on this list has an example use-case of call/cc in JS that you think
> is important, and that can't be mapped to coroutine-generators
> (Python 2.5, PEP 342), please post it.
I believe that the facilities of PEP 342, while necessary, is
insufficient, as it does not allow subroutines invoked by a coroutine
to yield for it, where some of the subroutines on the dynamic chain are
coroutine-blind (or if it does, it's too subtle for me to see how).
Lua (http://www.lua.org ) provides a particular flavor of coroutines
as its sole nonlinear control abstraction. Lua coroutines unite
generators, user-level multitasking, and backtracking into a single
fairly straightforward construct; I urge that they be considered.
Lua coroutines are asymmetric; that is, each coroutine returns only
to its caller, not to some arbitrary coroutine (though a coroutine
trampoline can overcome this restriction). Furthermore, a yield
can happen after arbitrarily many nested subroutine calls within
a coroutine. There's a short paper, which I strongly recommend, at
http://www.inf.puc-rio.br/~roberto/docs/corosblp.pdf that explains the
issues, the Lua coroutine syntax, a formal semantics, and points to some
interesting literature, including a demonstration that coroutines are
equivalent to one-shot delimited continuations; as is well known, call/cc
cannot provide arbitrary delimited continuations without recompiling
all uses.
Lua uses a slick implementation of its coroutines in pure C: Lua is
properly tail-recursive, and each Lua coroutine keeps its own stack
in the heap, but since coroutine invocation is entirely stack-like,
invocation is a recursive call into the Lua interpreter, and yield is a
return from the interpreter. The only restriction is that a C routine
called from Lua cannot yield.
--
You escaped them by the will-death John Cowan
and the Way of the Black Wheel. cowan at ccil.org
I could not. --Great-Souled Sam http://www.ccil.org/~cowan
More information about the Es4-discuss
mailing list