[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Coroutines [was: snapshot of Lua 4.1 (work)]
- From: "John Belmonte" <jvb@...>
- Date: Thu, 10 May 2001 13:36:48 +0900
Hi jc,
> That's a pity. If Lua were to avoid the C stack for ordinary function-
> call nesting, then coroutines (at the Lua-level) would be easy to
> implement - no special C code, and portable. Simply a closure which
> remembers the new_thread pointer, and saving/restoring the current VM
> instruction pointer on that stack for suspend/resume.
This issue has already been hashed out. Initially they planned to make 4.1
stackless. lhf had written:
> >Another
> >solution that would be nice if implemented in Lua would be to make
> >lua stackless. This way coroutines could easily be implemented in a
> >cross-platform way.
>
> That's the way we plan to do it in 4.1.
But here was Roberto's final word on it:
> > Presumably the hard bit is making it stay stackless when it calls C;
>
> The problem is that there are lots of places where Lua can make a
> call to C. Any tagmethod can be a C function, and so most basic operations
> may call C. Currently we handle calls to C and to Lua in the same way.
> To change that would break a nice "simetry" in the code, and would need
> lots of changes in the code. (It could also compromise performance...)
>
> We had three goals in mind: restricted co-rotines (only Lua), generic
> co-routines, and multi-thread. Lua stackless would demand lots of work,
and
> would solve only the first goal; it would be useless for the other two.
> Multiple stacks solves the other two goals (with a small external help),
it
> is quite simple to implement, and has no impact in performance.
-John