Link: The Lua folks discuss their implementation of coroutines, using Create, Resume and Yield methods.
Lua implements the concept of asymmetric coroutines, which are commonly denoted as semi-symmetric or semi-coroutines. Asymmetric coroutine facilities are so called because they involve two types of control transfer operations: one for (re)invoking a coroutine and one for suspending it, the latter returning control to the coroutine invoker. An asymmetric coroutine can be regarded as subordinate to its caller, the relationship between them being similar to that between a called and a calling routine.
Lua coroutine facilities provide three basic operations: create, resume and yield... Function coroutine.create creates a new coroutine, and allocates a separate stack for its execution... Function coroutine.resume (re)activates a coroutine, and receives as its required first argument the coroutine reference... A coroutine suspends by calling function coroutine.yield in this case, the coroutine’s execution state is saved and the corresponding call to coroutine.resume returns immediately.
The main difference with typical thread implementations is that (a). the caller is suspended until completion and (b). a coroutine can return values like a function call. I suppose I'd summarize it as functions that retain state between calls.
Recent comments
22 weeks 6 days ago
22 weeks 6 days ago
22 weeks 6 days ago
45 weeks 1 day ago
49 weeks 2 days ago
51 weeks 3 hours ago
51 weeks 3 hours ago
1 year 1 week ago
1 year 6 weeks ago
1 year 6 weeks ago