Mailboxes, Semaphores & Events
Passing transactions between testbench components, sharing a resource safely, and signalling between processes.
Parallel processes need to communicate. A mailbox is a thread-safe FIFO for passing objects (transactions) from one component to another. A semaphore holds keys that processes take and return to share a resource. An event lets one process wake others.
API summary
mailbox mb = new(); // untyped mailbox #(Txn) mb = new();
An untyped mailbox accepts anything, so a wrong type is only discovered at run time when get() fails. Parameterize it.
What is the difference between a bounded and an unbounded mailbox?
new() makes an unbounded mailbox where put() never blocks. new(N) holds at most N items; put() blocks while it is full, which naturally throttles a producer that runs ahead of the consumer.