Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Coroutine
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Definition and types == There is no single precise definition of coroutine. In 1980 Christopher D. Marlin<ref>{{cite book |last1=Marlin |first1=Christopher |title=Coroutines: A Programming Methodology, a Language Design and an Implementation |date=1980 |publisher=Springer |isbn=3-540-10256-6}}</ref> summarized two widely-acknowledged fundamental characteristics of a coroutine: # the values of data local to a coroutine persist between successive calls; # the execution of a coroutine is suspended as control leaves it, only to carry on where it left off when control re-enters the coroutine at some later stage. Besides that, a coroutine implementation has 3 features: # the control-transfer mechanism. ''Asymmetric coroutines'' usually provide keywords like <code>yield</code> and <code>resume</code>. Programmers cannot freely choose which frame to yield to. The runtime only yields to the nearest caller of the current coroutine. On the other hand, in ''symmetric coroutines'', programmers must specify a yield destination. # whether coroutines are provided in the language as [[First-class citizen|first-class objects]], which can be freely manipulated by the programmer, or as constrained constructs; # whether a coroutine is able to suspend its execution from within nested function calls. Such a coroutine is a ''stackful coroutine''. One to the contrary is called ''stackless coroutines'', where unless marked as coroutine, a regular function can't use the keyword <code>yield</code>. The paper "Revisiting Coroutines"<ref>{{cite journal|citeseerx=10.1.1.58.4017|author1=Ana Lucia de Moura|author2=Roberto Ierusalimschy|title=Revisiting Coroutines|journal=ACM Transactions on Programming Languages and Systems|volume=31|issue=2|pages=1β31|year=2009|doi=10.1145/1462166.1462167|s2cid=9918449}}</ref> published in 2009 proposed term ''full coroutine'' to denote one that supports first-class coroutine and is stackful. Full Coroutines deserve their own name in that they have the same [[Expressive power (computer science)|expressive power]] as one-shot [[Continuation|continuations]] and delimited continuations. Full coroutines are either symmetric or asymmetric. Importantly, whether a coroutine is symmetric or asymmetric has no bearing on how expressive it can be as they are equally as expressive, though full coroutines are more expressive than non-full coroutines. While their expressive power is the same, asymmetrical coroutines more closely resemble routine based control structures in the sense that control is always passed back to the invoker, which programmers may find more familiar.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)