Extrait du course LUA Symmetric and Asymmetric Coroutines
Coroutines
-An unconventional, but quite powerful control mechanism
-Well known as an abstract concept, but with several variations
-Variations with big differences
Kinds of Coroutines
-Symmetric or asymmetric
-Stackful
-First-class values
Symmetric and Asymmetric Coroutines
-Symmetric coroutines: one primitive for transfering control
-Typically called transfer
-Asymmetric coroutines: two primitives for transferring control
** Typically called resume and yield
resume/yield ↔ call/return
transfer ↔ goto
Stackful Coroutines
Non-stackful coroutines can be suspended only inside the body of the original function
Original concept (co-routine x sub-routine)
Stackful coroutines can be suspended while calling other functions
As implemented in Modula
Similar to cooperative multithreading
First-class Coroutines
Coroutines can be represented by first-class values
can be resumed anywhere in a program
Restricted forms of coroutines are not first class
e.g., generators in CLU and other languages
………
Course LUA Symmetric and Asymmetric Coroutines (116 Ko) (Cours PDF)