Concurrency vs Parallelism — Explained with Examples
Concurrency is about structuring multiple tasks that can run in overlapping time periods; parallelism is about running multiple tasks simultaneously.
Concurrency means dealing with many things at once (task structure). Parallelism means doing many things at once (execution). Concurrency enables parallelism but exists without it — on a single-core CPU, tasks can be concurrent (interleaved) but not parallel. Parallelism requires multiple cores or machines. Rob Pike’s quote: “Concurrency is about dealing with lots of things at once. Parallelism is about doing lots of things at once.”
Think of concurrency like juggling. A juggler handles multiple balls, throwing one, then another, and another — only one ball is in the air at a time on a single core (concurrent but not parallel). With two jugglers (two cores), they can throw simultaneously (parallel). The act of juggling is concurrency; actually having multiple balls in the air is parallelism.
Concurrent design separates concerns into independently executing processes, making programs easier to reason about and scale.
import threading
import multiprocessing
import time
# Concurrent (single core, interleaved)
def concurrent_example():
def task(name, delay):
for i in range(3):
print(f"Task {name}: step {i}")
time.sleep(delay)
t1 = threading.Thread(target=task, args=("A", 0.1))
t2 = threading.Thread(target=task, args=("B", 0.1))
t1.start(); t2.start()
t1.join(); t2.join()
# Parallel (multiple cores)
def parallel_example():
def task(name):
result = sum(i * i for i in range(10_000_000))
print(f"Task {name}: {result}")
p1 = multiprocessing.Process(target=task, args=("X",))
p2 = multiprocessing.Process(target=task, args=("Y",))
p1.start(); p2.start()
p1.join(); p2.join()Concurrent program design (decomposing into independent tasks) is a prerequisite for parallelism. Parallel execution is a performance optimization on top of concurrent structure.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro