[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: What's the difference between a "coroutine" and a "thread" in Lua?
- From: David Kastrup <dak@...>
- Date: Mon, 13 Aug 2007 15:09:42 +0200
Hugo Etchegoyen <email@example.com> writes:
> IMHO a non-preemptible thread and a coroutine (at least the kind of
> coroutines you are talking about, which have a private stack) are
> the same thing.
This would hold at best on single processors: on multiple processors,
several threads can run simultaneously unpreempted. However,
coroutines, being strictly synchronized, can have something that
threads in general don't: they can pass values. Yielding in a Lua
thread will both pass and accept a value to and from the controlling
Lua thread. This is obviously only possible when the caller is
suspended until the called thread yields. Apart from the switching of
the stacks, this is completely identical to function calls.