Jump to content

Structured concurrency

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Lucenty (talk | contribs) at 01:15, 24 October 2019 (set -> task tree). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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 that when control splits into concurrent tasks that they join up again, that any task error is propagated to the spawning scope (once the task's children and sibling tasks have completed), and that this control flow is readily evident by the structure of the source code. To be effective, this model must be applied consistently throughout all levels of the program-- otherwise concurrent tasks may leak out, become orphaned, or fail to have runtime errors correctly propagated.

The naming is inspired by structured programming, which created higher level control-flow statements out of the very basic goto. Similarly, structured concurrency creates higher level mechanisms for concurrency constructs out of the basic concurrent task creation constructs (spawn, threads, fibers).

The concept was formulated in 2016 by Martin Sústrik (creator of ZeroMQ)[1], and then further refined in 2018 by Nathaniel J. Smith, who implemented it in Trio.[2] Meanwhile, Roman Elizarov independently came upon the same ideas while developing an experimental coroutine library for the Kotlin language.[3][4]

Variations

A major point of variation is how an error in one member of a concurrent task tree is handled. Simple implementations will merely wait until the children and siblings of the failing task 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 tasks in an orderly manner.

See also

References

Citations

  1. ^ Sústrik, Martin (7 February 2016). "Structured Concurrency". Retrieved 1 August 2019.
  2. ^ Smith, Nathaniel J. (25 April 2018). "Notes on structured concurrency, or: Go statement considered harmful". Retrieved 1 August 2019.
  3. ^ Elizarov, Roman (12 September 2018). "Structured concurrency". Retrieved 21 September 2019.
  4. ^ Elizarov, Roman (July 2019). Structured concurrency (Videotape). 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.