---
title: "Message Passing and Asynchronous Work"
description: "Instead of sharing memory and guarding it, threads or processes can own their state and send messages. Queues, channels and event loops trade the race conditions of shared memory for questions about o"
canonical: https://lightmysky.com/learn/computing/message-passing-and-asynchronous-work-mt_twcpO-945r
source: https://lightmysky.com/learn/computing/message-passing-and-asynchronous-work-mt_twcpO-945r.md
retrieved: 2026-09-12
---

> **Agent view.** This is the Markdown twin of the page, for tools and assistants.
> When to use this site, and the call that answers each job: https://lightmysky.com/agent-instructions.md
> API description (OpenAPI 3.1): https://lightmysky.com/openapi.json · Authentication: https://lightmysky.com/auth.md
> Pricing: https://lightmysky.com/pricing.md · Catalog: https://lightmysky.com/llms.txt · Full catalog: https://lightmysky.com/llms-full.txt
> Every machine-readable file on this domain: https://lightmysky.com/.well-known/ai-catalog.json
> Ask for Markdown with `Accept: text/markdown`, a `.md` address, or `?mode=agent`.

# Message Passing and Asynchronous Work

Instead of sharing memory and guarding it, threads or processes can own their state and send messages. Queues, channels and event loops trade the race conditions of shared memory for questions about ordering, buffering and back pressure.

Subject: Computing · Area: Computer Systems · Ages 21 to 22
Page: https://lightmysky.com/learn/computing/message-passing-and-asynchronous-work-mt_twcpO-945r

## Ready when they can

- Rewrite a lock-based counter as a single owner served by a message queue
- Say what a bounded queue does when the producer outruns the consumer
- Compare the failure modes of shared memory and of message passing

## Lesson: Do Not Share, Just Send Word

Sharing memory means every thread can touch the same counter, so you guard it with locks and inherit their costs. Message passing takes the other road: each piece of state gets one owner, and everyone else sends messages. The owner of a counter reads one message at a time and applies it. No shared counter means no race on it.

**Example.** Turn a lock-based counter into messages. One worker owns the count, starting at zero. Other workers send notes like add 1 or add 2 into the owner's queue. The owner handles the notes one by one: add 1 makes 1, add 1 makes 2, add 2 makes 4. The lock is gone because only the owner ever touches the count.

The queue between workers has a limited size, so you must decide what happens when a fast producer outruns a slow consumer. First the queue buffers the extra messages. When the buffer fills, the system pushes back: the producer waits its turn, or the queue drops or refuses new messages, depending on the policy you chose. Fast producers cannot outrun reality forever.

**Tip.** Compare the failure modes before you pick a side. Shared memory fails with races and deadlocks around locks. Message passing removes those races on owned state, but adds new questions: a slow consumer, a full queue, dropped messages, and surprises in ordering. You trade one bug family for another.

**Recap.** Give each state one owner, send the rest as messages, size the queue, and pick which failure modes you would rather handle.

## Practice

8 questions on this page, each with its working shown.

## Needs first

- [Queues: First In, First Out](https://lightmysky.com/learn/computing/queues-first-in-first-out-mt_4U1bT0JW4g)
- [Deadlock and the Four Conditions](https://lightmysky.com/learn/computing/deadlock-and-the-four-conditions-mt_CsMOA4sBb1)

## Opens up

- [Training Across Many Devices: Data, Model and Pipeline Parallelism](https://lightmysky.com/learn/computing/training-across-many-devices-data-model-and-pipeline-parallelism-mt__e-JwIxHek)
- [Data Pipelines: Batch, Streaming and Doing It Twice](https://lightmysky.com/learn/computing/data-pipelines-batch-streaming-and-doing-it-twice-mt_o0zBEPLbmF)
