[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: About coroutines and light threads
- From: Edgar Toernig <froese@...>
- Date: Sun, 22 Oct 2000 20:57:27 +0200
Hi,
Just for your information. When Lua 4.0 is out, I will make a
version of Lua that will contain (beside other stuff) coroutines.
Coroutines are all you need to implement a lightweight cooperative
multitasking environment. I'll not take the route to make a
stackless Lua. IMHO that would cripple Lua. The tight coupling
between C and Lua will be lost. I'll take coroutines for C and
export them to Lua.
There's one downside of this: The coroutines will be optional
because they can't be implemented in a portable way. It requires
a couple of lines of assembler code. Currently supported are
x86 Linux and FreeBSD.
The upside: you not only get coroutines in Lua but also in C.
And, no feature of Lua will be lost. You just get a new one.
If you want concurrent/preemptive multitasking this will not
help. Then you better stick with POSIX threads or similar
stuff. Good luck.
setjmp/longjmp was mentioned to help with this and some people
were asking how? It's possible to implement coroutines with
the combination of setjmp/longjump and sigaltstack. But, it's
not much easier to port than a version with about a dozen lines
of assembler.
Btw, Python was mentioned several times. Don't only look at
stackless Python. There's also a Python-coro. eGroups.com is
completely written in it. It uses the same C coroutine library
that I'll take for Lua.
Ciao, ET.
PS: IMHO, coroutines are the most underrated programming technique.
They are more limited than continuations (Scheme) but normally,
continuations are only used to implement coroutines ;) And,
coroutines are much much lighter. They cost nothing during normal
program execution and only as much as a subroutine call to switch
from one coroutine to another.
And, they are _really_ easy to implement. Unfortunately only
in a system dependent way. But, putting it into the standard
C library would have increased its size by about 0.1%. Seems,
that was too much *ig*