Structured concurrency

Short description: Programming paradigm for improving clarity and development time of a computer program

Structured concurrency is a programming paradigm aimed at improving the clarity, quality, and development time of a computer program by using a structured approach to concurrent programming.

The core concept is the encapsulation of concurrent threads of execution (here encompassing kernel and userland threads and processes) by way of control flow constructs that have clear entry and exit points and that ensure all spawned threads have completed before exit. Such encapsulation allows errors in concurrent threads to be propagated to the control structure's parent scope and managed by the native error handling mechanisms of each particular computer language. It allows control flow to remain readily evident by the structure of the source code despite the presence of concurrency. To be effective, this model must be applied consistently throughout all levels of the program - otherwise concurrent threads may leak out, become orphaned, or fail to have runtime errors correctly propagated.

Structured concurrency is analogous to structured programming, which uses control flow constructs that encapsulate sequential statements and subroutines.

## Contents

* 1 History
* 2 Variations
* 3 See also
* 4 References
* 5 External links

## History

The fork–join model from the 1960s, embodied by multiprocessing tools like OpenMP, is an early example of a system ensuring all threads have completed before exit. However, Smith argues that this model is not true structured concurrency as the programming language is unaware of the joining behavior, and is thus unable to enforce safety.[1]

The concept was formulated in 2016 by Martin Sústrik (a developer of ZeroMQ) with his C library libdill, with goroutines as a starting point.[2] It was further refined in 2017 by Nathaniel J. Smith, who introduced a "nursery pattern" in his Python implementation called Trio.[3] Meanwhile, Roman Elizarov independently came upon the same ideas while developing an experimental coroutine library for the Kotlin language,[4][5] which later became a standard library.[6]

In 2021, Swift adopted structured concurrency.[7] Later that year, a draft proposal was published to add structured concurrency to Java.[8]

## Variations

A major point of variation is how an error in one member of a concurrent thread tree is handled. Simple implementations will merely wait until the children and siblings of the failing thread run to completion before propagating the error to the parent scope. However, that could take an indefinite amount of time. The alternative is to employ a general cancellation mechanism (typically a cooperative scheme allowing program invariants to be honored) to terminate the children and sibling threads in an expedient manner.

## See also

* Structured programming

## References

1. ↑ Smith, Nathaniel J. (25 April 2018). "Notes on structured concurrency, or: Go statement considered harmful". https://vorpus.org/blog/notes-on-structured-concurrency-or-go-statement-considered-harmful/.
2. ↑ Sústrik, Martin (7 February 2016). "Structured Concurrency". https://sustrik.github.io/250bpm/blog:71/.
3. ↑ Smith, Nathaniel J. (10 March 2017). "Announcing Trio". https://vorpus.org/blog/announcing-trio/.
4. ↑ Elizarov, Roman (12 September 2018). "Structured concurrency". https://medium.com/@elizarov/structured-concurrency-722d765aa952.
5. ↑ Elizarov, Roman (11 July 2019). Structured concurrency (Video). Hydra Distributed computing conference. 42 minutes in. Retrieved 21 September 2019. "We needed a name and we needed to finalize this whole concept [...] and we stumble onto this blog post [...] by Nathaniel J. Smith."
6. ↑ "Coroutines basics: Structured concurrency". JetBrains. https://kotlinlang.org/docs/coroutines-basics.html#structured-concurrency.
7. ↑ McCall, John; Groff, Joe; Gregor, Doug; Malawski, Konrad. "Swift Structured Concurrency Proposal". GitHub. https://github.com/apple/swift-evolution/blob/main/proposals/0304-structured-concurrency.md.
8. ↑ Pressler, Ron. "JEP draft: Structured Concurrency (Incubator)". Oracle. https://openjdk.java.net/jeps/8277129.

## External links

* Notes on structured concurrency, or: Go statement considered harmful by Nathaniel J. Smith
* Structured concurrency forum, cross-computer-language discussion of structured concurrency with participation by Sústrik, Smith, and Elizarov
* FOSDEM 2019: Structured Concurrency, lightning talk by Martin Sustrik with links to some implementations

* v
* t
* e

Programming paradigms

Imperative|

| Structured|

* Jackson structures
* Block-structured
* Modular
* Non-structured
* Procedural
* Programming in the large and in the small
* Design by contract
* Invariant-based
* Nested function

|

Object-oriented|

* Class-based, Prototype-based, Object-based
* Agent
* Immutable object
* Persistent
* Uniform function call syntax

Declarative|

| Functional|

* Recursive
* Anonymous function (Partial application)
* Higher-order
* Purely functional
* Total
* Strict
* GADTs
* Dependent types
* Functional logic
* Point-free style
* Expression-oriented
* Applicative, Concatenative
* Function-level, Value-level
* Monad

|

Dataflow|

* Flow-based
* Reactive (Functional reactive)
* Signals
* Streams
* Synchronous

Logic|

* Abductive logic
* Answer set
* Constraint (Constraint logic)
* Inductive logic
* Nondeterministic
* Ontology
* Probabilistic logic
* Query

Domain-
specific
language
(DSL)|

* Algebraic modeling
* Array
* Automata-based (Action)
* Command (Spacecraft)
* Differentiable
* End-user
* Grammar-oriented
* Interface description
* Language-oriented
* List comprehension
* Low-code
* Modeling
* Natural language
* Non-English-based
* Page description
* Pipes and filters
* Probabilistic
* Quantum
* Scientific
* Scripting
* Set-theoretic
* Simulation
* Stack-based
* System
* Tactile
* Templating
* Transformation (Graph rewriting, Production, Pattern)
* Visual

Concurrent,
parallel|

* Actor-based
* Automatic mutual exclusion
* Choreographic programming
* Concurrent logic (Concurrent constraint logic)
* Concurrent OO
* Macroprogramming
* Multitier programming
* Organic computing
* Parallel programming models
* Partitioned global address space
* Process-oriented
* Relativistic programming
* Service-oriented
* Structured concurrency

Metaprogramming|

* Attribute-oriented
* Automatic (Inductive)
* Dynamic
* Extensible
* Generic
* Homoiconicity
* Interactive
* Macro (Hygienic)
* Metalinguistic abstraction
* Multi-stage
* Program synthesis (Bayesian, by demonstration, by example, vibe coding)
* Reflective
* Self-modifying code
* Symbolic
* Template

Separation
of concerns|

* Aspects
* Components
* Data-driven
* Data-oriented
* Event-driven
* Features
* Literate
* Roles
* Subjects

Comparisons/Lists|

Comparison (multi-paradigm, object-oriented, functional), List (OO, by type)

0.00

(0 votes)

Original source: https://en.wikipedia.org/wiki/Structured concurrency. Read more

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Structured_concurrency&oldid=4156125"
*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template