Communicating Sequential Processes (CSP)
Overview
Communicating Sequential Processes (CSP) is a formal language and mathematical process calculus formulated by British computer scientist C.A.R. Hoare in 1978. It describes patterns of interaction in concurrent computing systems.
In CSP, concurrent systems are modeled as autonomous sequential processes that do not share state. Instead, they coordinate and exchange data exclusively through synchronous, first-class channels.
Core Axioms of CSP
- Processes: Independent sequential entities that transition through states via events.
- Events & Channels: Communication is an event shared simultaneously by both sender and receiver.
- Synchronous Rendezvous: In pure CSP, sending on a channel blocks until the receiving process is ready to receive (and vice versa), ensuring mutual agreement and ordering without shared locks.
- Alternative / Choice: A process can wait on multiple communication possibilities (the origin of Go’s
selectstatement and Occam’sALT).
CSP vs Actor Model
While both reject shared memory in favor of message passing:
- CSP (e.g., Go, Occam, Clojure core.async): Messages are sent to anonymous, typed channels. The sender does not necessarily know the identity of the recipient process. Communication is fundamentally synchronous (unbuffered rendezvous by default).
- Actor Model (e.g., Erlang/OTP, Akka): Messages are addressed directly to specific Actors (mailboxes). Communication is fundamentally asynchronous by default.
Modern Implementations
- The Go Programming Language (Golang): Implements CSP principles via Go Concurrency Model: Goroutines & Channels (goroutines and channels).
- Occam / Limbo: Direct historical ancestors of Go’s concurrency model designed by Rob Pike and others.
- Clojure
core.async: CSP implementation on the JVM.