RTL Studio Open IDE

3.3 · SYSTEMVERILOG CLASS

mailbox

Pass transactions between generator and driver threads with mailbox put/get.

Watch on YouTube

What you practice

mailbox (3.3). Pass transactions between generator and driver threads with mailbox put/get. It is in Timing & Synchronization — Part 3 · Advanced SV & Mini-UVM of the SystemVerilog Masterclass. Timing, concurrency, constrained-random verification, assertions, and a pure-SV Mini-UVM environment.

The same IDE is the SystemVerilog simulator. Slang lints the file, Verilator runs it, and the waveform viewer sits next to the source.

What you will learn

Today you will learn how to safely transfer transaction objects between concurrent threads using a SystemVerilog mailbox, enabling producer-consumer communication in testbenches.

Learning objectives

  • Declare and instantiate a typed mailbox.
  • Use put() to send transaction objects from a generator thread.
  • Use get() to receive transaction objects in a driver thread.
  • Understand blocking behavior and bounded capacity in mailbox operations.

Theory

A mailbox is a SystemVerilog class that provides thread-safe, blocking communication between concurrent processes. It supports bounded capacity (via constructor argument) and ensures atomic put() and get() operations. Unlike FIFOs, mailboxes are software constructs and do not synthesize to hardware. They are ideal for inter-process communication (IPC) in testbenches.

OperationBehavior
mbx.put(tx)Blocks if mailbox is full; otherwise stores tx.
mbx.get(rx)Blocks if mailbox is empty; otherwise retrieves into rx.
new(max_size)Creates mailbox with max capacity (max_size); default is unbounded if omitted.

Practice

Open this chapter in RtlStudio — all files appear in Explore. Edit only student/ files.

  1. Open student/tb/tb.sv in the editor.
  2. In the generator thread, replace mbx.__TODO__(tx) with the correct method call to send the transaction.
  3. In the driver thread, replace mbx.__TODO__(rx) with the correct method call to receive the transaction.
  4. Run Simulation → Run and check the Log panel for expected output.

Summary

You practiced using a mailbox to safely pass transaction objects between concurrent threads in a testbench. One thread used put() to enqueue objects while another used get() to dequeue them, ensuring synchronized communication. This reinforced the importance of thread-safe mechanisms in verification environments. The mailbox abstracts away race conditions, enabling reliable data exchange without explicit locking.

Run it in the Verilog IDE

  1. Open the lesson in the IDE. The SystemVerilog for this topic is already in the editor.
  2. Lint with Slang before you simulate. It covers both Verilog and SystemVerilog in this IDE.
  3. Run Verilator and inspect the VCD. Interfaces, classes, and assertions count only if the simulator agrees.
  4. Run Yosys when the lesson is synthesizable RTL, and keep testbench-only constructs out of that module.

The lesson is done when the simulation matches mailbox. Change the source, run the Verilog simulator again, and read the waveform without leaving the IDE. Simulation guide · Yosys guide.