Concept
Structured Concurrency
Structured concurrency treats concurrent work as a scoped tree so child tasks have clear lifetimes, cancellation, error propagation, and joining behavior.
Related languages
What Structured Concurrency Changes
Structured concurrency applies the same discipline to tasks that structured programming applies to control flow: concurrent work should have a clear lexical or logical scope. A parent starts child tasks, waits for them, cancels them when needed, and observes their errors before the scope exits.
This contrasts with fire-and-forget concurrency, where tasks can outlive the request, object, screen, command, or service operation that created them. Unstructured tasks are sometimes necessary, but they need explicit ownership.
Why It Helps
Structured concurrency makes cancellation and failure behavior easier to reason about. If one child fails, the runtime or library can cancel siblings and return an error to the parent. If a parent is cancelled, child work can be cancelled too. If the scope exits, the program should know what happened to all child tasks.
Kotlin coroutines, Swift concurrency, Python task groups, and Java structured task scopes all expose forms of this idea. The APIs differ, but the design pressure is the same: avoid lost tasks and hidden background failure.
Watch Points
Structured concurrency is not just an API label. Check how cancellation is delivered, whether blocking calls cooperate, how errors are aggregated, whether resources close on cancellation, and how task-local context behaves.
Long-lived daemons, supervisors, queues, and background services can still be structured, but their lifetime owner must be explicit.
Related Concepts
Structured concurrency connects Async Await And Event Loops, Goroutines And Green Threads, Threads And Shared Memory, and Testing Cultures.
Sources
Last verified:
- Coroutines guide JetBrains
- Swift Concurrency Swift Project
- asyncio Task Groups Python Software Foundation
- StructuredTaskScope Oracle