/kənˈkʌrənsi/
noun … “Multiple computations overlapping in time.”
Concurrency is the property of a system in which multiple tasks make progress within overlapping time periods, potentially sharing resources, but not necessarily executing simultaneously. It encompasses programming techniques that allow a single process or multiple processes to manage several independent flows of execution, improving responsiveness, resource utilization, and throughput. Concurrency is a broader concept than parallelism: while parallelism implies simultaneous execution on multiple CPUs or cores, Concurrency includes interleaved execution on a single core as well.
Implementations of Concurrency involve mechanisms like Threading, Multiprocessing, asynchronous programming (async/await), and event-driven architectures. In interpreted languages like Python, the GIL affects CPU-bound concurrency by serializing execution of Python bytecode within a single process, whereas I/O-bound tasks benefit from interleaving threads or asynchronous tasks to maintain high responsiveness.
Key characteristics of Concurrency include:
- Interleaved execution: tasks appear to progress simultaneously even on single-core systems.
- Shared resources: concurrency often requires synchronization to prevent race conditions, deadlocks, or data corruption.
- Non-deterministic ordering: task execution order may vary depending on scheduling, I/O timing, or system load.
- Scalability: well-designed concurrent systems can leverage multi-core and distributed environments efficiently.
Workflow example: A Python web server handles multiple incoming requests. Using Threading or asynchronous coroutines, each request is processed independently. While one thread waits for database I/O, other threads continue serving requests. CPU-intensive computation may be offloaded to separate processes using Multiprocessing to bypass the GIL and achieve true parallelism.
Conceptually, Concurrency is like a restaurant kitchen with multiple chefs sharing limited space and ingredients. Tasks are interleaved to keep orders moving efficiently. Chefs coordinate to avoid collisions (data conflicts), ensuring each dish is completed promptly while maximizing overall throughput.
See Threading, Multiprocessing, Global Interpreter Lock, Python.