all about vlsi DV
Events & Mailboxes in SystemVerilog — Synchronization Made Easy
1. Introduction
So far, Alice and Bob have learned to:
-
Run things in parallel (fork–join)
-
Decide when to wait
But a new problem appears:
How does Alice tell Bob that something has happened?
How does Bob wait safely without guessing time delays?
This is where events and mailboxes come in.
They solve synchronization, not storage.
2. What Are Events and Mailboxes?
(Featured Snippet Target)
In SystemVerilog, events are used for signaling that something has happened, while mailboxes are used for synchronized data transfer between processes.
In short:
-
Event → signal without data
Mailbox → signal + data
3. Alice & Bob Setup (Keep This Picture)
-
Alice produces something
-
Bob waits for it
-
Alice does not know when Bob is ready
-
Bob does not want to poll or guess delays
They need a clean handshake.
4. Events — “Something Happened”
Mental Picture (Very Important)
Alice says:
“Hey Bob, I’m done!”
She doesn’t send data.
She just signals.
Bob waits patiently until that signal arrives.
That is an event.
Runnable Example — Event Signaling
module event_example;
event done;
initial begin
#10;
-> done; // Alice triggers event
$display("Alice: work done at %0t", $time);
end
initial begin
@done; // Bob waits
$display("Bob: noticed completion at %0t", $time);
end
endmodule
What to Remember
-
-> event triggers
-
@event waits
-
No data is transferred
👉 Event = notification only
5. When Events Are the Right Choice
Use events when:
-
Only timing matters
-
No data needs to be shared
-
One process must wake another
Examples:
-
Test phase complete
-
Reset released
Timeout expired
6. Mailboxes — “Here Is the Data”
Mental Picture (Memorize This)
Alice produces data and drops it into a box.
Bob opens the box when he’s ready and takes the data.
If the box is empty:
-
Bob waits
If the box is full:
-
Alice may wait (optional)
That box is a mailbox.
Runnable Example — Mailbox Communication
module mailbox_example;
mailbox mb = new();
initial begin
#10;
mb.put(42); // Alice puts data
$display("Alice sent data");
end
initial begin
int data;
mb.get(data); // Bob waits until data arrives
$display("Bob received %0d", data);
end
endmodule
What to Remember
-
put() → producer
-
get() → consumer
-
Synchronization + data transfer
👉 Mailbox = safe producer–consumer
7. Event vs Mailbox (One Clear Comparison)
Aspect | Event | Mailbox
Carries data No Yes
Synchronization Yes Yes
Producer–consumer Weak Strong
Common usage Signals Transactions
If data matters → mailbox
If only notification matters → event
8. Common Beginner Mistakes
-
Using delays (#) instead of events
-
Using events when data is required
-
Forgetting get() blocks if mailbox is empty
Overusing mailboxes for simple signaling
9. Interview Perspective (Very Important)
Interviewers often ask:
-
“Difference between event and mailbox?”
-
“When would you use mailbox over event?”
-
“Is mailbox blocking?”
Strong One-Line Answers
-
Event is signal-only
-
Mailbox synchronizes data transfer
get() blocks until data arrives
10. Interview Questions (Inside the Article)
Easy
-
What problem do events solve?
-
Can an event carry data?
Medium
-
What happens if get() is called on an empty mailbox?
-
When is mailbox preferred over event?
Hard
-
Why are mailboxes safer than shared variables?
-
Can multiple producers use the same mailbox?
-
What kind of bugs do events help eliminate?
Try answering these before moving on.
11. One Sentence to Remember (Interview Gold)
Event wakes a process; mailbox hands over data safely.
If you remember this, you won’t confuse them.
12. What’s Next
Now Alice and Bob can:
-
Signal each other
-
Exchange data safely
Next, Alice wants to:
Model behavior using real-world objects.
👉 Next Article:
Classes in System Verilog — Object-Oriented Basics
This is where System Verilog starts feeling very different from Verilog.