Concurrency models define how programs handle multiple tasks simultaneously, whether through parallel execution on multiple cores or interleaved execution on a single core. Different programming languages adopt fundamentally different approaches — message passing (Go, Erlang), shared memory (Java, C++), async/await (JavaScript, Python), and ownership-based (Rust) — each optimized for different classes of problems. The landscape spans from low-level atomic operations and memory ordering to high-level abstractions like actors and CSP channels. Understanding these models is essential because the choice shapes performance, safety, and complexity: a lock-based approach may deadlock where a message-passing design cannot, and an async runtime may outperform threads for I/O-bound work while underperforming for CPU-bound tasks.
What This Cheat Sheet Covers
This topic spans 12 focused tables and 89 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
Table 1: Fundamental Concurrency Models
| Model | Example | Description |
|---|---|---|
Thread t = new Thread(() -> doWork());t.start(); | • OS-managed units of execution • threads share memory, processes are isolated • threads have lower overhead but require synchronization | |
case class Message(data: String)actor ! Message("hello") | • Isolated actors communicate via asynchronous messages • each actor processes messages sequentially • popular in Erlang/Elixir/Akka • avoids shared state | |
ch := make(chan int)ch <- 42 | • Channels for message passing between goroutines • anonymous communication (vs. actor identities) • core abstraction in Go and Clojure core.async | |
async def fetch(): await asyncio.sleep(1) | • Cooperative multitasking using async functions that yield at await points • single-threaded event loop schedules coroutines • ideal for I/O-bound workloads | |
Fiber.new { sleep 1 }.resume | • User-space threads scheduled by runtime (not OS) • lower context-switch overhead • Ruby fibers and pre-1.2 Go goroutines are examples |