Message Passing and Asynchronous Work
A message-passing counter can have one owner that applies queued updates one at a time. This removes shared-counter races, but queue capacity, overload, ordering and blocking still need design. Asynchronous requests let callers continue before a result is ready.
What a learner can do afterwards
- 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
1 · Read
You have seen races and deadlocks with shared counters and locks. In this message-passing design, one worker owns the counter. Other workers send update messages; they never read or write the counter directly. The owner finishes one update before starting the next, so updates do not interleave. Starting at 0, it handles add 1, add 1, then add 2 to reach 4. The counter needs no lock between senders, though the queue still needs safe concurrent access.
Bounded queues have fixed capacity. Full-queue policy blocks sends, rejects them or drops messages. Back pressure blocks or slows producers; dropping alone does not. Sustained overload needs fewer arrivals or faster processing. Extra capacity absorbs finite bursts, not a lasting rate gap. Unbounded queues can exhaust memory.
With constant rates, an empty queue, enough space and no drops, subtract the number handled from arrivals each second. Multiply that gain by elapsed seconds. If 6 arrive and 4 are handled each second, after 2 seconds: (6 - 4) × 2 = 4 queued.
FIFO removes messages in enqueue order, not necessarily the application's required order. Starting one producer first does not determine which send arrives first. Separate FIFO queues need a merge rule. If a coordinator requires A before B, it can enqueue both in that order.
Asynchronous requests let callers continue before completion. Replies may arrive out of order or never arrive. Match replies by request ID and define a missing-reply policy, such as a timeout. Asynchronous calling does not speed up the work or require the owner to handle messages concurrently.
Serial ownership removes sender races on this counter. Shared state needs coordination; locks can deadlock. Messages can be lost, misordered or blocked by full queues. Two workers blocking on full outgoing queues instead of receiving can deadlock.
One serial owner removes races on its counter. Define queue limits, overload policy and required order. For asynchronous requests, match replies to requests and handle failure.
Original lesson, questions and flashcards about single-owner message passing and asynchronous requests, authored for this dataset.
Original reading and flashcards about asynchronous requests, replies and message queues, authored for this dataset.
2 · Watch
Take it off screen
Where it sits
Learn first
Optional connections
8 questions wait behind this lesson, each with its answer explained. Every answer feeds the sky: stars light as they are learned, and dim when it is time to come back.