Concurrency
Also known as: Concurrent computing
Ability of a program or system to make progress on several tasks during overlapping time periods, whether or not they literally run simultaneously.
Concurrency is the structuring of a program as multiple tasks whose lifetimes overlap. A web server handling many users, a phone running apps while downloading updates and a game updating physics while playing sound are all concurrent. Concurrency is distinct from parallelism: concurrent tasks may be interleaved on a single processor core, switching back and forth, whereas parallel tasks literally execute at the same instant on different cores. A common way to put the difference is that concurrency is about dealing with many things at once, while parallelism is about doing many things at once.
Programs achieve concurrency through processes, threads, coroutines or event loops, and the hard part is coordination. When tasks share data, operations can interleave in unexpected ways and produce race conditions; when tasks wait on each other, they can deadlock. Edsger Dijkstra tackled these problems in the 1960s, publishing a solution to the mutual exclusion problem in 1965 and introducing the semaphore as a synchronization tool. Tony Hoare's 1978 paper on communicating sequential processes proposed coordinating through messages instead of shared memory, an idea that later influenced the channels of the Go language.
Concurrency matters because most real systems must respond to many independent events, and because since the mid-2000s chipmakers have increasingly added processor cores rather than raising clock speeds. Languages offer different models for managing the risk: locks and mutexes, message passing between isolated actors as in Erlang, async/await and ownership rules like those in Rust that reject many data races at compile time. Concurrency bugs are notoriously hard to reproduce, because they depend on timing that can vary from one run to the next.
Key points
- Concurrency means tasks overlap in time, while parallelism means they run at literally the same moment.
- Shared data and mutual waiting make concurrent programs prone to race conditions and deadlocks.
- Edsger Dijkstra and Tony Hoare laid foundations for coordinating concurrent processes in the 1960s and 1970s.
- Common models include threads with locks, message passing between actors, async/await and compile-time ownership checks.
Related entries
Parallel Computing
Form of computation in which many calculations run simultaneously on multiple processors or cores to solve problems faster or at larger scale.
Race Condition
Flaw in which a system's behavior depends on the uncontrolled timing or ordering of events, such as two threads updating the same data at once.
Deadlock
Situation in which two or more processes are each waiting for another to release a resource, so that none of them can ever proceed.
Asynchronous Programming
Programming approach that lets a program start long-running operations, such as network requests, and continue other work until the results arrive.
Event Loop
Programming construct that repeatedly waits for events, such as user input or completed network requests, and dispatches each to its handler.
Edsger Dijkstra
Dutch computer scientist known for his shortest path algorithm, structured programming and foundational work on concurrency and program correctness.
Go
Statically typed, compiled programming language designed at Google for simplicity, fast builds and built-in concurrency, widely used for cloud software.
Rust
Systems programming language that guarantees memory safety without a garbage collector through its ownership model, first stable in 2015.
Referenced by
Other entries that discuss or point to Concurrency.