[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Coroutines...
- From: "Stefano Lanzavecchia" <stf@...>
- Date: Thu, 10 May 2001 10:32:08 +0200
> Well, it will not help a lot. The corolib only supports X86
> Linux and FreeBSD. I never got any patches for other architectures.
The Win32 API has native support for coroutines. They are called Fibers
and they work (I used them to implement coroutines in Lua 4.0 beta). It
would he really easy to wrap the native Win32 API calls so that they
have the same aspect as the coro library.
> Date: Wed, 9 May 2001 20:43:17 -0700
> From: Jean-Claude Wippler <jcw@equi4.com>
> Subject: Coroutines [was: snapshot of Lua 4.1 (work)]
>
> Ouch. C-level co-routines? My first reaction was: why not
> simply implement them at the Lua level? Oh, of course: Lua
> intermingles the C call stack with its own... like Tcl and
> standard Python - and unlike Stackless Python (which
> implements "calling" without nesting the C stack). SP's
> trick is to have the VM push and pop call frames, instead of
> going through a C function which nests the VM.
Stackless Python still doesn't solve the problem of Python calling a C
routine calling Python. And the problem is the same with Lua. A lot of
Lua users would start a Lua script, which calls into a custom C routine
which calls Lua again (on the same environment). And this pattern can be
nested ad-libitum. Plus all the hooks can, once again, nest the stack.
There is no way you can avoid this unless you change the C compilers to
implement a stackless C call. Since this is by far the most common usage
of Lua, it must be taken into account. You could prevent coroutine
switching if you detected a pending C call on the stack, allowing
coroutines to work only if at the toplevel. I suspect this pure
implementation would impose limitations, reasonable for some users, and
unacceptable for others.
> 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.
Indeed. I tried once to rewrite the VM to avoid C stack for ordinary Lua
function-call (once again, on beta 4.0). I got it to work on everything
EXCEPT TAILCALL which has a strange semantic (it's not what I would call
a tail-call since it grows the stack!). Yet, because of the reasons I
just mentioned, I was much happier when I discovered that it was easy to
implement coroutines letting Win32 do all the dirty work for me.
Here's a good starting point:
http://msdn.microsoft.com/library/default.asp?URL=/library/psdk/winbase/
prothred_5mur.htm
--
WildHeart'2k1 - mailto:stf@apl.it
Homepage: http://come.to/wildheart/
<<<Anche oggi ho imparato qualcosa! ---
-- Kintaro Oe>>>