Concurrent computing is a form of computing in which several computations are executed concurrently—during overlapping time periods—instead of sequentially—with one completing before the next starts.
This is a property of a system—whether a program, computer, or a network—where there is a separate execution point or "thread of control" for each process. A concurrent system is one where a computation can advance without waiting for all other computations to complete.
Concurrent computing is a form of modular programming. In its paradigm an overall computation is factored into subcomputations that may be executed concurrently. Pioneers in the field of concurrent computing include Edsger Dijkstra, Per Brinch Hansen, and C.A.R. Hoare.
Concurrency is a broader concept that encompasses several related ideas, including:
Parallelism (simultaneous execution on multiple processing units). Parallelism executes tasks independently on multiple CPU cores. Concurrency allows for multiple threads of control at the program level, which can use parallelism or time-slicing to perform these tasks. Programs may exhibit parallelism only, concurrency only, both parallelism and concurrency, or neither.
Multi-threading and multi-processing (shared system resources)
Synchronization (coordinating access to shared resources)
Coordination (managing interactions between concurrent tasks)
Concurrency Control (ensuring data consistency and integrity)
Inter-process Communication (IPC, facilitating information exchange)
Concurrency refers to the ability of a system to execute multiple tasks through simultaneous execution or time-sharing (context switching), sharing resources and managing interactions. Concurrency improves responsiveness, throughput, and scalability in modern computing, including:
Operating systems and embedded systems
Distributed systems, parallel computing, and high-performance computing
Database systems, web applications, and cloud computing
The concept of concurrent computing is frequently confused with the related but distinct concept of parallel computing, although both can be described as "multiple processes executing during the same period of time". In parallel computing, execution occurs at the same physical instant: for example, on separate processors of a multi-processor machine, with the goal of speeding up computations—parallel computing is impossible on a (one-core) single processor, as only one computation can occur at any instant (during any single clock cycle). By contrast, concurrent computing consists of process lifetimes overlapping, but execution does not happen at the same instant. The goal here is to model processes that happen concurrently, like multiple clients accessing a server at the same time. Structuring software systems as composed of multiple concurrent, communicating parts can be useful for tackling complexity, regardless of whether the parts can be executed in parallel.
For example, concurrent processes can be executed on one core by interleaving the execution steps of each process via time-sharing slices: only one process runs at a time, and if it does not complete during its time slice, it is paused, another process begins or resumes, and then later the original process is resumed. In this way, multiple processes are part-way through execution at a single instant, but only one process is being executed at that instant.[citation needed]
Concurrent computations may be executed in parallel, for example, by assigning each process to a separate processor or processor core, or distributing a computation across a network.
The exact timing of when tasks in a concurrent system are executed depends on the scheduling, and tasks need not always be executed concurrently. For example, given two tasks, T1 and T2:[citation needed]
T1 may be executed and finished before T2 or vice versa (serial and sequential)
T1 and T2 may be executed alternately (serial and concurrent)
T1 and T2 may be executed simultaneously at the same instant of time (parallel and concurrent)
The word "sequential" is used as an antonym for both "concurrent" and "parallel"; when these are explicitly distinguished, concurrent/sequential and parallel/serial are used as opposing pairs. A schedule in which tasks execute one at a time (serially, no parallelism), without interleaving (sequentially, no concurrency: no task begins until the prior task ends) is called a serial schedule. A set of tasks that can be scheduled serially is serializable, which simplifies concurrency control.[citation needed]
The main challenge in designing concurrent programs is concurrency control: ensuring the correct sequencing of the interactions or communications between different computational executions, and coordinating access to resources that are shared among executions. Potential problems include race conditions, deadlocks, and resource starvation. For example, consider the following algorithm to make withdrawals from a checking account represented by the shared resource balance:
Suppose balance = 500, and two concurrent threads make the calls withdraw(300) and withdraw(350). If line 3 in both operations executes before line 5 both operations will find that balance >= withdrawal evaluates to true, and execution will proceed to subtracting the withdrawal amount. However, since both processes perform their withdrawals, the total amount withdrawn will end up being more than the original balance. These sorts of problems with shared resources benefit from the use of concurrency control, or non-blocking algorithms.
There are advantages of concurrent computing:
Increased program throughput—parallel execution of a concurrent algorithm allows the number of tasks completed in a given time to increase proportionally to the number of processors according to Gustafson's law.
High responsiveness for input/output—input/output-intensive programs mostly wait for input or output operations to complete. Concurrent programming allows the time that would be spent waiting to be used for another task.
More appropriate program structure—some problems and problem domains are well-suited to representation as concurrent tasks or processes. For example MVCC.
Because computations in a concurrent system can interact with each other while being executed, the number of possible execution paths in the system can be extremely large, and the resulting outcome can be indeterminate. Concurrent use of shared resources can be a source of indeterminacy, leading to issues such as deadlocks, and resource starvation.
Design of concurrent systems often entails finding reliable techniques for coordinating their execution, data exchange, memory allocation, and execution scheduling to minimize response time and maximize throughput.
Concurrency theory has been an active field of research in theoretical computer science. One of the first proposals was Carl Adam Petri's seminal work on Petri nets in the early 1960s. In the years since, a wide variety of formalisms have been developed for modeling and reasoning about concurrency.
A number of formalisms for modeling and understanding concurrent systems have been developed, including:
The parallel random-access machine
The actor model
Computational bridging models such as the bulk synchronous parallel (BSP) model
Petri nets
Process calculi Calculus of communicating systems (CCS) Communicating sequential processes (CSP) model π-calculus
Tuple spaces, e.g., Linda
Simple Concurrent Object-Oriented Programming (SCOOP)
Reo Coordination Language
Trace monoids
Some of these models of concurrency are primarily intended to support reasoning and specification, while others can be used through the entire development cycle, including design, implementation, proof, testing, and simulation of concurrent systems. Some of these are based on message passing, while others have different mechanisms for concurrency.
The proliferation of different models of concurrency has motivated some researchers to develop ways to unify these different theoretical models. For example, Lee and Sangiovanni-Vincentelli have demonstrated that a so-called "tagged-signal" model can be used to provide a common framework for defining the denotational semantics of a variety of different models of concurrency, while Nielsen, Sassone, and Winskel have demonstrated that category theory can be used to provide a similar unified understanding of different models.
The Concurrency Representation Theorem in the actor model provides a fairly general way to represent concurrent systems that are closed in the sense that they do not receive communications from outside. (Other concurrency systems, e.g., process calculi can be modeled in the actor model using a two-phase commit protocol.) The mathematical denotation denoted by a closed system S is constructed increasingly better approximations from an initial behavior called ⊥S using a behavior approximating function progressionS to construct a denotation (meaning) for S as follows:
In this way, S can be mathematically characterized in terms of all its possible behaviors.
Various types of temporal logic can be used to help reason about concurrent systems. Some of these logics, such as linear temporal logic and computation tree logic, allow assertions to be made about the sequences of states that a concurrent system can pass through. Others, such as action computational tree logic, Hennessy–Milner logic, and Lamport's temporal logic of actions, build their assertions from sequences of actions (changes in state). The principal application of these logics is in writing specifications for concurrent systems.
Introduced in 1962, Petri nets were an early attempt to codify the rules of concurrent execution. Dataflow theory later built upon these, and Dataflow architectures were created to physically implement the ideas of dataflow theory. Beginning in the late 1970s, process calculi such as Calculus of Communicating Systems (CCS) and Communicating Sequential Processes (CSP) were developed to permit algebraic reasoning about systems composed of interacting components. The π-calculus added the capability for reasoning about dynamic topologies.
Input/output automata were introduced in 1987.
Logics such as Lamport's TLA+, and mathematical models such as traces and Actor event diagrams, have also been developed to describe the behavior of concurrent systems.
Software transactional memory borrows from database theory the concept of atomic transactions and applies them to memory accesses.
Concurrent programming languages and multiprocessor programs must have a consistency model (also known as a memory model). The consistency model defines rules for how operations on computer memory occur and how results are produced.
One of the first consistency models was Leslie Lamport's sequential consistency model. Sequential consistency is the property of a program that its execution produces the same results as a sequential program. Specifically, a program is sequentially consistent if "the results of any execution is the same as if the operations of all the processors were executed in some sequential order, and the operations of each individual processor appear in this sequence in the order specified by its program".
A number of different methods can be used to implement concurrent programs, such as implementing each computational execution as an operating system process, or implementing the computational processes as a set of threads within a single operating system process.
In some concurrent computing systems, communication between the concurrent components is hidden from the programmer (e.g., by using futures), while in others it must be handled explicitly. Explicit communication can be divided into two classes:
Shared memory and message passing concurrency have different performance characteristics. Typically (although not always), the per-process memory overhead and task switching overhead is lower in a message passing system, but the overhead of message passing is greater than for a procedure call. These differences are often overwhelmed by other performance factors.
Concurrent computing developed out of earlier work on railroads and telegraphy, from the 19th and early 20th century, and some terms date to this period, such as semaphores. These arose to address the question of how to handle multiple trains on the same railroad system (avoiding collisions and maximizing efficiency) and how to handle multiple transmissions over a given set of wires (improving efficiency), such as via time-division multiplexing (1870s).
The academic study of concurrent algorithms started in the 1960s, with Dijkstra (1965) credited with being the first paper in this field, identifying and solving mutual exclusion.
Concurrency is pervasive in computing, occurring from low-level hardware on a single chip to worldwide networks. Examples follow.
At the programming language level:
Channel
Coroutine
Futures and promises
At the operating system level:
Computer multitasking, including both cooperative multitasking and preemptive multitasking Time-sharing, which replaced sequential batch processing of jobs with concurrent use of a system
Process
Thread
At the network level, networked systems are generally concurrent by their nature, as they consist of separate devices.
Concurrent programming languages are programming languages that use language constructs for concurrency. These constructs may involve multi-threading, support for distributed computing, message passing, shared resources (including shared memory) or futures and promises. Such languages are sometimes described as concurrency-oriented languages or concurrency-oriented programming languages (COPL).
Today, the most commonly used programming languages that have specific constructs for concurrency are Java and C#. Both of these languages fundamentally use a shared-memory concurrency model, with locking provided by monitors (although message-passing models can and have been implemented on top of the underlying shared-memory model). Of the languages that use a message-passing concurrency model, Erlang was probably the most widely used in industry as of 2010.[citation needed]
Many concurrent programming languages have been developed more as research languages (e.g., Pict) rather than as languages for production use. However, languages such as Erlang, Limbo, and occam have seen industrial use at various times in the last 20 years. A non-exhaustive list of languages that use or provide concurrent programming facilities:
Ada – general purpose, with native support for message passing and monitor based concurrency
Alef – concurrent, with threads and message passing, for system programming in early versions of Plan 9 from Bell Labs
Alice – extension to Standard ML, adds support for concurrency via futures
Ateji PX – extension to Java with parallel primitives inspired from π-calculus
Axum – domain specific, concurrent, based on actor model and .NET Common Language Runtime using a C-like syntax
Binary Modular Dataflow Machine (BMDFM)
C++ – thread and coroutine support libraries
Cω (C omega) – for research, extends C#, uses asynchronous communication
C# – supports concurrent computing using lock, yield, also since version 5.0 async and await keywords introduced
Clojure – modern, functional programming dialect of Lisp on the Java platform
Concurrent Clean – functional programming, similar to Haskell
Concurrent Collections (CnC) – achieves implicit parallelism independent of memory model by explicitly defining flow of data and control
Concurrent Haskell – lazy, pure functional language operating concurrent processes on shared memory
Concurrent ML – concurrent extension of Standard ML
Concurrent Pascal – by Per Brinch Hansen
Curry
D – multi-paradigm system programming language with explicit support for concurrent programming (actor model)
E – uses promises to preclude deadlocks
ECMAScript – uses promises for asynchronous operations
Eiffel – through its SCOOP mechanism based on the concepts of Design by Contract
Elixir – dynamic and functional meta-programming aware language running on the Erlang VM, which uses asynchronous message passing with no shared memory
Erlang – dynamic and functional language running on the Erlang VM, which uses asynchronous message passing with no shared memory
FAUST – real-time functional, for signal processing, compiler provides automatic parallelization via OpenMP or a specific work-stealing scheduler
Fortran–coarrays and do concurrent are part of Fortran 2008 standard
Go – for system programming, with a concurrent programming model based on communicating sequential processes (CSP)
Haskell – concurrent, and parallel functional programming language
Hume – functional, concurrent, for bounded space and time environments where automata processes are described by synchronous channels patterns and message passing
Io – actor-based concurrency
Janus – features distinct askers and tellers to logical variables, bag channels; is purely declarative
Java – thread class or Runnable interface
Julia – concurrent programming primitives: tasks, async-wait, channels
JavaScript – via web workers, in a browser environment, promises, and callbacks
JoCaml – concurrent and distributed channel based, extension of OCaml, implements the join-calculus of processes
Join Java – concurrent, based on Java language
Joule – dataflow-based, communicates by message passing
Joyce – concurrent, teaching, built on Concurrent Pascal with features from CSP by Per Brinch Hansen
LabVIEW – graphical, dataflow, functions are nodes in a graph, data is wires between the nodes; includes object-oriented language
Limbo – relative of Alef, for system programming in Inferno (operating system)
Locomotive BASIC – Amstrad variant of BASIC contains EVERY and AFTER commands for concurrent subroutines
MultiLisp – Scheme variant extended to support parallelism
Modula-2 – for system programming, by Niklaus Wirth as a successor to Pascal with native support for coroutines
Modula-3 – modern member of ALGOL family with extensive support for threads, mutexes, condition variables
Newsqueak – for research, with channels as first-class values; predecessor of Alef
occam – influenced highly by communicating sequential processes (CSP) occam-π – modern variant of occam, includes ideas from Milner's π-calculus
Object REXX (ooRexx) – object-based, message exchange for communicating and synchronizing
Orc – highly concurrent, nondeterministic, based on Kleene algebra
Oz-Mozart – multiparadigm, supports shared-state and message-passing concurrency, and futures
ParaSail – object-oriented, parallel, free of pointers, race conditions
PHP – multithreading support with parallel extension implementing message passing inspired from Go
Pict – basically an executable implementation of Milner's π-calculus
Python – uses thread-based parallelism and process-based parallelism
Raku – includes classes for threads, promises and channels by default
Reia – uses asynchronous message passing between shared-nothing objects
Red/System – for system programming, based on Rebol
Rust – for system programming, using message-passing with move semantics, and shared memory (immutable and mutable)
Scala – general purpose, designed to express common programming patterns in a concise, elegant, and type-safe way
SequenceL – general purpose functional, main design objectives are ease of programming, code clarity-readability, and automatic parallelization for performance on multicore hardware, and provably free of race conditions
SR – for research
SuperPascal – concurrent, for teaching, built on Concurrent Pascal and Joyce by Per Brinch Hansen
Swift – built-in support for writing asynchronous and parallel code in a structured way
Unicon – for research
TeleNokia Specification and Description Language (TNSDL) – for developing telecommunication exchanges, uses asynchronous message passing
VHSIC Hardware Description Language (VHDL) – IEEE STD-1076
XC – concurrency-extended subset of C language developed by XMOS, based on communicating sequential processes, built-in constructs for programmable I/O
Many other languages provide support for concurrency in the form of libraries, at levels roughly comparable with the above list.
Asynchronous I/O
Chu space
Client–server network nodes
Clojure
Cluster nodes
Concurrency control
Concurrency pattern
Concurrent computing
Concurrent object-oriented programming
Construction and Analysis of Distributed Processes (CADP)
D (programming language)
Dining philosophers problem
Distributed system
Elixir (programming language)
Erlang (programming language)
Flow-based programming
Go (programming language)
Gordon Pask
International Conference on Concurrency Theory (CONCUR)
Java ConcurrentMap
OpenMP
Parallel computing
Partitioned global address space
Pony (programming language)
Processes
Ptolemy Project
Race condition § Computing
Rust (programming language)
Sheaf (mathematics)
Structured concurrency
Threads
Transaction processing
X10 (programming language)
