← Lessons

quiz vs the machine

Gold1420

Concurrency

Channels and the CSP Model

Communicating Sequential Processes share by communicating.

5 min read · core · beat Gold to climb

Processes joined by channels

In Communicating Sequential Processes, independent processes run on their own and coordinate only by passing values over channels. The slogan is do not communicate by sharing memory, share memory by communicating.

Synchronous rendezvous

A classic CSP channel is unbuffered: a send blocks until a receiver is ready, and a receive blocks until a sender arrives. The handoff is a rendezvous where both sides meet at the same instant. This synchronizes the two processes without any lock.

Buffered channels

A buffered channel holds up to N values. A send only blocks when the buffer is full; a receive only blocks when it is empty. Buffering decouples producer and consumer speeds and provides natural backpressure: a fast producer stalls once the buffer fills.

Why channels compose

Channels are first class values, so you can pass a channel over a channel, fan work out to a pool, and fan results back in. Pipelines become a graph of small processes, each doing one job.

Closing

A closed channel signals that no more values will come, letting consumers drain and exit cleanly instead of guessing.

Key idea

CSP processes coordinate by sending values over channels; the channel itself provides synchronization and backpressure.

Check yourself

Answer to earn rating on the learn ladder.

1. What happens on a send to an unbuffered channel with no waiting receiver?

2. How does a buffered channel provide backpressure?