Work it through
Ordered blocked requests
The timestamps establish which request entered the blocked waiting queue first; FIFO then preserves that order.
A resumes before B in this deliberately ordered, equal-key fixture.
Your next page is on its way.
Chapter 1 · Communication & synchronization
Select communication and synchronization primitives from their persistence, capacity, ownership, and wakeup guarantees.

A worked mechanism
Queue arrival order and same-time process scheduling are different questions.
available = 0
A semaphore starts with new(0). All requests in this example need one key.
waiting order: A, B
A calls get(1) at 1 ns; B calls get(1) at 2 ns. Both block.
A obtains the key
A third process calls put(1) at 3 ns.
B obtains the key
After A releases its key, the next queued request can proceed.
Work it through
The timestamps establish which request entered the blocked waiting queue first; FIFO then preserves that order.
A resumes before B in this deliberately ordered, equal-key fixture.
Concurrent callers at the same timestamp have no source-order arrival guarantee. This does not establish bounded fairness or a single global ordering across immediate get, try_get, and differently sized requests.
Record arrival and acquisition separately. Verify key balance and that both requests were actually blocked before keys return.
The language bench / mailbox
mailbox #(int) mb = new(1);
mb.try_put(value); // 0 when full
mb.try_peek(value); // reads without removing
mb.try_get(value); // consumes one messageQuestion-first preparation
Each question maps directly to one of the sections below, so you can test the contract before reading the explanation.
One representative prompt from each major mechanism. Open any card in the live question bank.
Message transfer
Mailbox put/get operations provide atomic communication and optional capacity. Correctness still depends on producer count, consumer count, termination, type safety, and whether sent objects are copied or shared.
Bounded channel
Blocks when the bounded mailbox is full.
Atomic ordering and capacity, but no automatic end-of-stream.
Blocks when empty and removes the oldest message.
A sentinel, count, or phase protocol terminates both sides.
Blocks when the bounded mailbox is full.
A mailbox is a synchronization and communication boundary. Capacity, end-of-stream behavior, and any separate ownership handoff belong in its public contract.
Count producers, consumers, maximum outstanding messages, blocking operations, termination tokens, and shared class handles.
Choose blocking put/get for backpressure, try_put/try_get for explicit polling, and peek only when consuming later is safe.
A final put can deadlock after consumers stop, and sending a class handle can create a race if the producer mutates the same object afterward.
Assert bounded occupancy, count sends and receives, run empty/full schedules, and poison or clone transferred objects according to ownership policy.
put waits for capacity, get waits for an item, and peek waits for an item without removing it. A system is live only when another active process can satisfy each wait. Count operations along every shutdown path, not just the steady-state loop.
typedef struct {
bit last;
int value;
} item_t;
mailbox #(item_t) channel = new(4);
task automatic produce();
for (int i = 0; i < 10; i++)
channel.put('{last: 0, value: i});
channel.put('{last: 1, value: 0});
endtask
task automatic consume();
item_t item;
forever begin
channel.get(item);
if (item.last) break;
check(item.value);
end
endtaskWith a bounded mailbox, two gets do not guarantee that three later puts can complete. If the consumer stops after its second get, the final put may wait forever once capacity is exhausted. Build a balance table that includes the channel's initial and final occupancy.
| Method | Blocks? | Removes? | Use |
|---|---|---|---|
| put | If full | Adds | Backpressured send |
| try_put | No | Adds on success | Explicit retry or drop policy |
| get | If empty | Yes | Returns a value or handle; no automatic clone or ownership transfer |
| try_get | No | On success | Nonblocking receive |
| peek | If empty | No | Inspect next item |
| try_peek | No | No | Conditional inspection |
| num | No | No | Diagnostic snapshot, not atomic admission |
Explain it out loud
A mailbox provides atomic put/get operations and blocking synchronization. A shared queue still needs locking, notification, capacity, and shutdown logic around every access.
Good answers connect communication with synchronization, not only container syntax.
Assuming mailbox transfer deep-copies a class object.
Balance all puts and gets, include initial capacity and shutdown messages, and show that every blocking operation has a concurrently runnable process capable of satisfying it.
The key concept is liveness across all schedules, not merely matching source-code counts.
Counting two gets and two puts while ignoring a final sentinel put.
Resources and notifications
Semaphores count permits and events publish transient notifications. Neither stores arbitrary state, so late arrivals, fairness, reset, and cancellation need separate design.
Synchronization selector
Acquire N units; release exactly N units.
Waiter must already be listening.
True only for the remainder of the slot in which e fired.
Late observers can discover that completion already occurred.
Acquire N units; release exactly N units.
Choose a primitive whose memory matches the protocol: count, transient notification, or persistent completion.
For each wait, ask whether the condition is a resource count, a transient occurrence, or a state that must remain true for late observers.
Use get/put for permits, @event for the next trigger, wait(event.triggered) for current-slot observation, and a bit/counter/mailbox for persistence.
A late @event waiter misses an earlier trigger, and a missing semaphore put leaks capacity until all later users block.
Track permits with assertions, randomize waiter arrival, test trigger-before-wait and wait-before-trigger, and verify reset and cancellation paths.
new(K) creates K keys. get(N) blocks until N are available and then atomically removes them; try_get(N) returns immediately; put(N) returns capacity. The owner must release permits on every normal, error, timeout, and cancellation path.
semaphore ports = new(2);
task automatic use_port(input int id);
bit acquired = 0;
ports.get(1);
acquired = 1;
begin
automatic int status = transact(id);
if (status != 0) $error("transaction %0d failed", id);
end
if (acquired) ports.put(1);
endtask@done waits for a future trigger and misses one that already happened. wait(done.triggered) can observe a trigger anywhere in the current time slot, but the property is not sticky across time slots. Use a persistent done bit, counter, barrier, or message when completion must be remembered.
| Need | Primitive | Late waiter behavior |
|---|---|---|
| Next occurrence | @event | Misses earlier trigger |
| Occurrence in current slot | wait(event.triggered) | Sees same-slot trigger only |
| Remembered completion | bit/counter plus event | Reads state immediately |
| One payload per notification | mailbox | Payload remains queued |
| N arrivals before release | barrier/counter protocol | State persists until phase advances |
Explain it out loud
No. It is true only for the remainder of the simulation time slot in which the event triggered. Use separate state when a waiter arriving later must still observe completion.
The expected phrase is “current time slot,” not “one clock cycle.”
Treating triggered like a sticky boolean property.
The blocked waiting queue is FIFO: queued get requests retain their arrival order. This does not define which simultaneous caller reaches the queue first, guarantee bounded progress, or establish a global ordering across immediate get and try_get calls.
Strong answers distinguish resource safety from progress fairness.
Building protocol correctness around the observed wakeup order of one simulator.