Programming Paradigms · Session 8 · Message passing
The relevance of message passing
Message passing is the model of concurrent computation in which processes share no data that can change and affect one another only by sending values: each process owns its state, and a message can be received only after it has been sent.
In a shared-memory program, nondeterminism can enter at any conflicting, unordered access to shared data, and nothing in the program text marks which accesses those are. Message passing confines it to the points where processes meet. The central question of the session is how each of its systems resolves a contested communication: a point at which more than one process is ready and only one can be served next.
Three resolutions of a contested communication
The systems of the session give three answers. The first removes the contest altogether; the second and the third are the session's two blocks, each named by the resolution its languages make the default.
- No contest. In a Kahn process network (Kahn, 1974, in the account by
Lee and Parks, 1995)
every process is deterministic, every channel has one writer and one reader, a read waits on one
named channel, and no process chooses among its inputs. The sequence of values on every channel is
then the same under every fair schedule, and the network pays for it in waiting. A shell pipeline such as
grep x | sort | uniqis one with bounded pipes in place of Kahn's unbounded queues, which can make it wait or stall but never change its output. - A guarded choice in the program. In Hoare's CSP (1978), in occam and in Go, the programmer marks a choice point, and the language takes one of the partners ready there. A timeout is one more branch of the choice, with the clock as the sender.
- Arrival order in a queue. In Hewitt's actors (1973) and in Erlang, senders drop their messages into one mailbox without waiting, and the mailbox's order of arrival, not the program, settles a contest between senders. Erlang keeps the order between each pair of processes; a receive takes the oldest message that matches one of its patterns, and earlier messages that match none stay in the mailbox.
The RC 4000 nucleus, Copenhagen, 1969
The earliest system of the session was built in Copenhagen. At Regnecentralen, the group of Per Brinch Hansen wrote for the RC 4000 computer a small nucleus whose basic means of communication between processes were messages; device handling and process control stayed inside it, and operating systems ran on top of it as ordinary processes. The paper, “The Nucleus of a Multiprogramming System”, appeared in Communications of the ACM in April 1970, and the design is an early published form of the idea behind microkernels. Its primitive wait message serves a process's queue first come, first served, the third resolution, and two further primitives let a process serve the queue in any order; its replies travel back in the buffer of the request, a conversation identified and checked by the nucleus, which no other process can contest.
The nucleus also shows where the shared memory went. Its pool of message buffers and its queues are touched by every process, through the nucleus, which runs each message primitive with interrupts disabled until it completes or suspends its caller: in effect one global lock around its message handling. A Go channel today is a runtime structure with a buffer, queues of waiting goroutines and a lock. On one machine, message passing does not remove shared memory; it hides it in one trusted place, which has to be right only once.
The cost of message passing
Removing the shared data trades one kind of failure for another: waiting replaces racing. A handshake with no partner never completes, and a program in which every process waits is deadlocked; when every goroutine waits, Go's runtime stops the program with the message below. A study of 171 concurrency bugs in six large Go systems, by Tu, Liu, Song and Zhang (ASPLOS 2019), found that message passing caused more of the blocking bugs than shared memory, and far fewer of the non-blocking ones.
fatal error: all goroutines are asleep - deadlock!
The lost update of sessions 6 and 7 returns as well, without any shared variable. Two clients that each read a counter server's value in one message and write it back plus one in another can lose an increment, although the server's own code is sequential. The repair is a protocol in which the invariant is carried by one message.
Message passing is the model of Go and Erlang, of Rust's channels, of the browser's workers and of microkernels, whose line is generally seen to start with the nucleus. Actors are also libraries and language features: on the JVM (Akka and Apache Pekko, its fork of Akka 2.6), in .NET (Orleans), in Swift (since Swift 5.5, 2021). The languages differ in what a message carries: after the send, a value may be shared, copied or moved, and a different party checks each case.
Message passing, by language and system
GoGuarded choice · sharing by convention
Go, made public in November 2009, has channels and
select in the language; its
specification states that a select takes one of its ready cases by “a uniform pseudo-random
selection”. Effective Go gives the rule
“share memory by communicating”, and the rule is a convention: a pointer sent on a channel stays
shared, the compiler accepts the program, and the race detector reports only the races it observes
in an instrumented run.
Kubernetes,
Docker and
etcd are written in Go.
Erlang and ElixirArrival order · copied values
Erlang, whose development
began at Ericsson in 1986 and which was
released as open
source in December 1998, has processes with mailboxes as its unit of concurrency. The
virtual machine copies a message into the receiver's heap, except large binaries and literals, which it shares
by reference; since the data is immutable, no sharing can be observed; the
order between each pair of processes is kept; a send to the pid of a dead process returns normally, while a send to a registered name that no
longer exists raises badarg; a monitor turns a death into a 'DOWN' message, where session 9 begins.
WhatsApp's servers and
RabbitMQ are
built on Erlang; Elixir, on the same virtual machine, was the language of
Discord's
first prototype and of the infrastructure that grew from it.
RustMove of ownership · compiler check
Rust's channels
(std::sync::mpsc) move the value sent: the send takes ownership of it, and the
compiler rejects a use of the value after the send as a “borrow of moved value”. A value of a Copy type, an integer for instance, is
copied instead. A value that must
stay shared travels as an Arc, a counted handle, and can then be changed only through
a type that synchronizes its own access, such as a Mutex, an RwLock or an atomic. Session 12 states the rule of ownership.
The web browserCopy or transfer
A page's web workers share no
JavaScript objects with it and communicate with it by postMessage.
The HTML standard copies the
message by structured cloning; an object in the transfer list, an ArrayBuffer for
instance, is moved instead and is no longer usable on the sending side: two of the three cases, a
copy and a move, in one call. Chromium itself is split into processes that communicate through the
message pipes of Mojo.
MicrokernelsMessage passing in the kernel
The nucleus's design, a small kernel whose processes communicate by messages, is generally seen as the start of the line of today's microkernels, although the nucleus kept device handling inside it. In QNX, message passing is the primary form of communication between processes, and BlackBerry states, in its report for the quarter ended 31 August 2026, that QNX runs in more than 275 million vehicles. seL4, a member of the L4 family, became in 2009 the first operating-system kernel with a machine-checked proof of functional correctness; its threads communicate through kernel objects called endpoints.
Message passing is also how AI systems are put together: the processes are workers on accelerators, model servers and agents, and the messages are tasks, results and tool calls.
Message passing and AI
RayActors
Ray, which its own site calls “the framework behind ChatGPT”, and which OpenAI used to train its largest model, has actors: an actor is a stateful worker, an instance of a class that runs in its own Python process, and a call of one of its methods is a message sent to it. When delivery is no longer assumed, faults become the subject; session 9 starts from a crash on one machine.
Agent frameworksThe actor model
Microsoft's AutoGen, a framework for systems of cooperating AI agents, was rebuilt in January 2025 on “a scalable, event-driven actor framework”, in which agents communicate through asynchronous messages. The actor model was itself proposed for artificial intelligence: Hewitt's paper of 1973 was titled “A Universal Modular ACTOR Formalism for Artificial Intelligence”.
Tool callsIdentified conversations
An AI assistant calls its tools through the Model Context Protocol, whose messages are JSON-RPC 2.0: a request carries an id, and its response “MUST include the same ID”. The client matches each reply to its request by that id, as an Erlang client matches a reference and the RC 4000 nucleus a buffer. Google's Agent2Agent protocol, announced in April 2025 for messages between agents and moved to the Linux Foundation in June 2025, is JSON-RPC 2.0 over HTTP as well.
Agent graphsMessage passing between nodes
In LangGraph, a library for workflows of language-model agents, a program is a graph of nodes, and its documentation states that the underlying graph algorithm “uses message passing to define a general program”, after Google's Pregel system.
ServingProcesses and sockets
vLLM, a server for language-model inference, runs its API server and its engine core as separate processes that communicate “via ZMQ sockets”, ZeroMQ's message queues: the requests that reach the server travel as messages to the engine core, which schedules them on the GPU.
Learning objectives
In the session
- Explain where nondeterminism enters a program with shared memory, at any unordered pair of conflicting accesses, and where it enters a program that passes messages: only where processes communicate, provided they share nothing else, messages carry values rather than pointers, and no process is nondeterministic inside itself.
- Explain why a Kahn process network, whose processes are deterministic and sequential, with one writer and one reader per channel, blocking reads and no choice, produces the same sequences on its channels under every fair schedule, and what it pays for that in waiting.
- Classify each communication point of a program as uncontested, resolved by a guarded choice in the program, resolved by arrival order in a queue, or left to the runtime where the language does not say, and say which outcomes the program can therefore produce; name the two resolutions the RC 4000 nucleus used.
- Recognize a deadlock by waiting in a Go program, a state in which goroutines wait forever for a communication that no goroutine will offer (Go's runtime reports it only when every goroutine is blocked), and name its usual causes: a missing send, a missing receive, a channel never closed.
- State what actor theory guarantees (eventual delivery, whole messages, one message handled at a time, sends only to known addresses) and what it leaves out (order, a bound on delay, a reply), and state that Erlang keeps the order of messages between each pair of processes, and how a client process matches a reply to its request by a reference and a selective receive.
- Explain how a server that owns its state loses an update across two messages, a read in one and a write in the next, without any shared variable, and why one message per operation prevents it.
In the lab
The objectives of the lab are published with the lab.
27 October 2026. Each claim about a current system is linked to its source in the text. Logos are the organizations' GitHub avatars.