Any advantage on stack-less python implen开发者_JAVA百科tation than Lua's coroutine? What's the difference of them?
stackless python and tasklets (I haven't done any programming with stackless python, but I have read some of the details about how it is implemented):
Pros:
- Lightweight most of the time.
- Has scheduler to manage which tasklet get resume next after the current one yields.
- Support for Preemptive Scheduling. (i.e. run for X instructions)
- Channels for communication between tasklets.
Cons:
- Sometimes need C-stack when yielding from a tasklet. (i.e. when yielding from some C callbacks)
Lua 5.1 with plain coroutines:
Pros:
- Lightweight.
- resume()/yield() functions allow consumer/producer model of communication.
Cons:
- No built-in scheduler. You have to manage resuming & yielding coroutines.
- Can't yield from a C function, a metamethod, or an iterator. (Lua 5.2 will remove most of these restrictions, LuaJIT 1.1 provides lightweight c-stack switching to yield from anywhere)
- No built-in Preemptive Scheduling support. (would have to use debug hooks)
Lua 5.1 with ConcurrentLua:
Pros:
- Lightweight.
- Scheduler with cooperative context switching.
- Has Erlang style of message passing communication between tasks.
- Support for transparent distributed message passing between nodes.
Cons:
- Can't yield from a C function, a metamethod, or an iterator. (again most of these restrictions go-away with Lua 5.2 and LuaJIT)
- No built-in Preemptive Scheduling support. (would have to use debug hooks)
LuaJIT 2.0 Beta with ConcurrentLua:
Pros:
- Lightweight.
- Scheduler with cooperative context switching.
- Has Erlang style of message passing communication between tasks.
- Support for transparent distributed message passing between nodes.
- Very fast JIT support makes Lua much faster then Python
Cons:
- Might not be able to yield from a C function right now. This might be supported in future releases.
- No built-in Preemptive Scheduling support. (would have to use debug hooks)
精彩评论