Skip to content

Coroutines

Coroutines are computer program components that can be suspended and resumed — generalizing subroutines — for cooperative multitasking.

Core Idea

Coroutines is treated here as the recurring computing and information systems identity summarized by this source-grounded definition: Coroutines are computer program components that can be suspended and resumed — generalizing subroutines — for cooperative multitasking. Coroutines are computer program components that can be suspended and resumed — generalizing subroutines — for cooperative multitasking. Coroutines are well-suited for implementing familiar program components such as cooperative tasks, exceptions, event loops, iterators, infinite lists and pipes. They have been described as "functions whose execution you can pause".

How would you explain it like I'm…

Pause-and-Continue Helpers

Imagine reading a bedtime story, stopping at a bookmark, playing a game, and later opening the story right where you left off. Coroutines are pieces of a computer program that can pause like that and pick up again later, taking turns with other pieces.

Taking-Turns Program Parts

A computer program is made of pieces that do jobs. Usually, a piece starts, runs until it's finished, and then hands control back. A coroutine is a special piece that can pause in the middle, let another piece run, and later continue exactly where it stopped, remembering everything. The pieces politely take turns instead of being interrupted, which is called cooperative multitasking. This is handy for things like producing a long list one item at a time or passing data down a line of steps.

Suspendable Resumable Routines

Coroutines are program components that can be suspended and later resumed, keeping their state in between. They generalize subroutines (ordinary functions): a subroutine runs from start to finish each time it's called, while a coroutine can stop partway, hand control elsewhere, and continue from the same point — 'functions whose execution you can pause.' Because each coroutine chooses when to give up control, they support cooperative multitasking, as opposed to a system that forcibly switches between tasks. They're a natural way to build iterators, event loops, pipelines, infinite lists, and cooperative tasks. The term was coined by Melvin Conway in 1958.

 

Coroutines are program components that can be suspended and resumed, generalizing subroutines, and are used for cooperative multitasking. Where a subroutine has a single entry and runs to completion before returning, a coroutine can yield control mid-execution and later resume from that point with its local state preserved. Control transfer is voluntary, which distinguishes cooperative multitasking from preemptive scheduling. Coroutines are well suited to implementing cooperative tasks, exceptions, event loops, iterators, infinite lists, and pipes. Melvin Conway coined the term in 1958 for the construction of an assembly program, and the first published explanation appeared in 1963. Whether coroutines are symmetric or asymmetric does not affect their expressive power, but full coroutines are more expressive than non-full ones.

Scope of Application

  • Assembly languages. Once a second call stack has been obtained with one of the methods listed above, the setjmp and longjmp functions in the standard C library can then be used to implement.

  • Assembly languages. This is the approach recommended by Tom Duff in a discussion on its relative merits vs. the method used by Protothreads.

  • Java. There are four general methods used, but two break bytecode portability among standards-compliant JVMs.

  • Java. These use JNI methods implemented in the OS or C libraries to provide the functionality to the JVM.

  • Assembly languages. This can be significantly faster, as setjmp and longjmp must conservatively store all registers which may be in use according to the ABI, whereas the clobber method allows the compiler to.

Clarity

A clear use of Coroutines names the carrier, the operative relation, and the conditions under which the source treats the identity as present. The minimal definition is Coroutines are computer program components that can be suspended and resumed — generalizing subroutines — for cooperative multitasking. The strongest recognition evidence in the frozen account is: By contrast, coroutines can exit by calling other coroutines, which may later return to the point where they.

Manages Complexity

Coroutines compresses multiple computing and information systems details into a stable diagnostic relation. The source shows both the central mechanism—go has a built-in concept of "goroutines", a type of green thread which are lightweight, independent processes managed by the Go runtime.—and the practical consequence—coroutines provide concurrency, because they allow tasks to be performed out of order or in a changeable order, without changing the overall outcome, but.

Abstract Reasoning

  1. Type the carrier. Identify the computing and information systems entities to which the claim applies.
  2. State the relation. Use the source-grounded identity: Coroutines are computer program components that can be suspended and resumed — generalizing subroutines — for cooperative multitasking.
  3. Check operation and conditions. whether coroutines are provided in the language as first-class objects, which can be freely manipulated by the programmer, or as constrained constructs.
  4. Demand recognition evidence.

Knowledge Transfer

Within the home domain. Knowledge about Coroutines transfers literally when a new case preserves the same carrier type, relation, and recognition test. Once a second call stack has been obtained with one of the methods listed above, the setjmp and longjmp functions in the standard C library can then be used to implement the switches between coroutines. This is the approach recommended by Tom Duff in a discussion on its relative merits vs. the method used by Protothreads. Beyond the home domain. No canonical parent is asserted for Coroutines.

Neighborhood in Abstraction Space

Coroutines sits in a sparse region of the domain-specific corpus (82nd percentile for distinctiveness): few abstractions share its structure, so a faithful description tends to retrieve it precisely.

Family — Computation Models & Complexity Classes (37 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-10-08