wait in SystemVerilog: @event vs wait(event.triggered), wait(expression) and wait fork, Tested on VCS
In short: In SystemVerilog, @(ev) waits for the next trigger of an event, so it misses a trigger that already happened. wait(ev.triggered) also catches a trigger from earlier in the same time step, but not from an earlier time step. wait(expression) returns at once if the expression is already true, and wait fork waits for every child process. In UVM, uvm_event::wait_on() is the call that remembers a trigger across time.
A testbench is full of processes that wait for each other: a monitor waits for a driver, a scoreboard waits for a monitor, a test waits for everything. The classic bug is a wait that starts a moment too late and hangs forever.
I put every kind of wait into one UVM test and ran it on VCS. Every time below is what the log printed, in ns.
A simple way to picture it
Think of an event as a doorbell. @(ev) is standing at the door listening: you hear the bell only if it rings after you got there.
wait(ev.triggered) is checking the doorbell’s light, which stays on until the end of that moment. Come a moment later and the light is off. wait(expression) is just looking at the door: if it’s already open, you walk in.
The ways to wait, in one table
| Statement | Returns when | Misses |
|---|---|---|
@(ev) |
the next trigger after it starts | a trigger earlier in the same time step |
wait(ev.triggered) |
the event was triggered in this time step, now or later | a trigger in an earlier time step |
wait(expression) |
the expression is true, at once if it already is | nothing; it’s level-sensitive |
@(signal) |
the next change of the signal | a value that’s already there |
wait fork |
every child process of this process has finished | nothing |
uvm_event::wait_on() |
the event is on, at once if it already is | nothing until reset() |
The rest of this post is the run that backs up each row.
1. The waiter is there first
Both waiters started at 0 and the trigger came at 1 ns. Both woke up.
@ 1: [TAV_1] -> e1
@ 1: [TAV_1] @(ev) woke up
@ 1: [TAV_1] wait(ev.triggered) woke up
When the waiter is first, @ and wait(ev.triggered) behave the same. The difference only shows when the trigger wins the race.
2. The trigger wins the race in the same time step
At 11 ns the test triggered e2, then started both waiters in the same time step.
@ 11: [TAV_2] -> e2, then the waiters start in the same time step
@ 11: [TAV_2] wait(ev.triggered) woke up
@ 16: [TAV_2] @(ev) still waiting after 5 ns, giving up
wait(ev.triggered) woke at 11. @(ev) had missed the trigger and would have waited forever without the 5 ns timeout.
This is the classic event race. In a real bench it shows up when a driver triggers “item done” at the same time a monitor starts waiting for it.
3. The waiter is one time step late
The trigger came at 26 ns and both waiters started at 27 ns.
@ 26: [TAV_3] -> e3
@ 27: [TAV_3] waiters start 1 ns after the trigger
@ 32: [TAV_3] @(ev) still waiting after 5 ns, giving up
@ 32: [TAV_3] wait(ev.triggered) still waiting after 5 ns, giving up
Both missed it. The triggered state only lasts until the end of the time step the trigger happened in.
So wait(ev.triggered) fixes a race inside one time step, not a handshake across time. If the waiter can be a whole cycle late, you need a flag, a mailbox or uvm_event::wait_on().
4. The nonblocking trigger ->>
->> schedules the trigger for later in the same time step instead of firing it right away. At 42 ns the test did ->> e4 and then started @(e4).
@ 42: [TAV_4] ->> e4, then @(e4) starts in the same time step
@ 42: [TAV_4] @(ev) woke up
This time @ caught it, because the trigger landed after the waiter was already listening. It’s another way out of the part 2 race, chosen on the side that triggers.
5. wait(ev.triggered) inside a loop
->e5;
n = 0;
repeat (1000) begin
wait(e5.triggered);
n++;
end
@ 52: [TAV_5] loop passed wait(e5.triggered) 1000 times, time did not move
Once the event is triggered, wait(e5.triggered) returns straight away every time until the time step ends. In a forever loop with nothing else that takes time, that’s a zero-delay loop and the simulation hangs.
6. uvm_event: wait_trigger() and wait_ptrigger()
Most UVM benches use uvm_event instead of a raw event. The name wait_ptrigger(), the “persistent” trigger wait, suggests it remembers a trigger from 1 ns earlier.
@ 62: [TAV_6] ue.trigger(), then wait 1 ns
@ 68: [TAV_6] wait_trigger() still waiting after 5 ns, giving up
@ 73: [TAV_6] wait_ptrigger() still waiting after 5 ns, giving up
@ 73: [TAV_6] is_on() = 1 before reset()
It didn’t. is_on() was 1, so the event knew it had been triggered, but wait_ptrigger() waited anyway.
The UVM source explains it: wait_ptrigger() checks m_event.triggered, the same flag as part 3, so it only helps inside the trigger’s own time step. wait_on() checks the event’s on flag, which stays set until reset().
7. uvm_event: same time step, and wait_on()
Part 8 of the bench checked both of those claims.
@ 101: [TAV_8] same time step: wait_ptrigger() returned
@ 102: [TAV_8] 1 ns later: wait_on() returned
wait_ptrigger() returned when it ran in the trigger’s time step. wait_on() returned 1 ns after the trigger, straight away.
So for “has this happened yet?” across time, use wait_on(). After reset() the event is off again; in the run, wait_ptrigger() after reset() gave up at 78 ns.
uvm_event can also carry data. wait_trigger_data() returned at 80 ns with the object I passed to trigger(), named “tav_payload”.
8. Two handles, one event
An event variable is a handle. After e7b = e7a, both names point to the same event.
@ 91: [TAV_7] -> e7a (the waiter is on e7b)
@ 91: [TAV_7] @(ev) woke up
The waiter on e7b woke up when the test triggered e7a. That’s handy for passing an event into a task, and a surprise if you thought you had two separate events.
9. wait(expression) vs @(signal)
This is what most people searching “systemverilog wait” want. wait(expression) is level-sensitive: it checks the value, and returns at once if it’s already true.
@ 112: [TAV_9] wait(ready == 1) returned at once, ready was already 1
@ 117: [TAV_9] @(ready) still waiting after 5 ns, giving up
ready was already 1 when both waiters started. wait(ready == 1) returned at 112, and @(ready) waited for a change that never came.
Use wait() for “until this is true” and @ for “until this changes”. Mixing them up is the same race as part 2, just on a signal.
10. wait fork
wait fork blocks until every child process the current process started has finished. I started two children with join_none, one taking 3 ns and one 7 ns.
@ 127: [TAV_10] parent: join_none returned, now wait fork
@ 130: [TAV_10] child A done
@ 134: [TAV_10] child B done
@ 134: [TAV_10] parent: wait fork returned
The parent moved on at 127, then wait fork held it until the slower child finished at 134. It’s the usual way to let a test start background threads and still wait for them at the end.
Which one should you use?
- Same time step race between two processes:
wait(ev.triggered)on the waiting side, or->>on the triggering side. - “Has it happened yet?” across time: a
uvm_eventwithwait_on(), or a plain flag withwait(flag). - Wait for a value:
wait(expression). - Wait for an edge or a change:
@. - Wait for background threads:
wait fork.
The bench: one file, one run
Everything above comes from one file, tav_event_wait.sv: one UVM test with ten parts, every result printed with `uvm_info and its time. Every wait has a 5 ns timeout, so the run always ends.
On EDA Playground, paste it into testbench.sv, leave design.sv empty, pick UVM 1.2 and press Run (download it as a zip, 2 KB).
The full code: tav_event_wait.sv
// tav_event_wait.sv : @(ev) vs wait(ev.triggered), plus uvm_event, in one UVM test.
// The Art of Verification (theartofverification.com)
//
// Run on: Synopsys VCS with UVM 1.2 (EDA Playground).
// Paste into testbench.sv, leave design.sv empty. Top module: tav_top.
// All messages go through `uvm_info; the @ time in each line is in ns.
//
// Parts, one after another (each starts on a new 10 ns boundary):
// 1. waiter starts before the trigger: @ev and wait(ev.triggered)
// 2. trigger and waiter in the same time step, trigger first
// 3. waiter starts one time step after the trigger
// 4. nonblocking trigger ->> in the same time step
// 5. wait(ev.triggered) inside a loop
// 6. uvm_event: wait_trigger() vs wait_ptrigger(), and trigger data
// 7. two event handles that point to one event
// 8. uvm_event: wait_ptrigger() in the trigger's time step, and wait_on() 1 ns later
// 9. wait(expression) on a value that is already true, vs @(expression)
// 10. wait fork
// Every wait has a timeout, so the run always ends.
`timescale 1ns/1ns
`include "uvm_macros.svh"
package tav_ev_pkg;
import uvm_pkg::*;
class tav_msg extends uvm_object;
`uvm_object_utils(tav_msg)
function new(string name = "tav_msg");
super.new(name);
endfunction
endclass
class tav_ev_test extends uvm_test;
`uvm_component_utils(tav_ev_test)
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
// wait for ev with @ or with wait(triggered); give up after 5 ns
task tav_at(string id, event ev);
fork
begin @(ev); `uvm_info(id, "@(ev) woke up", UVM_LOW) end
#5 `uvm_info(id, "@(ev) still waiting after 5 ns, giving up", UVM_LOW)
join_any
disable fork;
endtask
task tav_wt(string id, event ev);
fork
begin wait(ev.triggered); `uvm_info(id, "wait(ev.triggered) woke up", UVM_LOW) end
#5 `uvm_info(id, "wait(ev.triggered) still waiting after 5 ns, giving up", UVM_LOW)
join_any
disable fork;
endtask
virtual task run_phase(uvm_phase phase);
event e1, e2, e3, e4, e5, e7a, e7b;
bit ready;
uvm_event ue;
uvm_object data;
int n;
phase.raise_objection(this);
// ------------------------------------------- 1. waiters first, trigger at +1
`uvm_info("TAV_1", "both waiters start, trigger comes 1 ns later", UVM_LOW)
fork
tav_at("TAV_1", e1);
tav_wt("TAV_1", e1);
begin #1 `uvm_info("TAV_1", "-> e1", UVM_LOW) ->e1; end
join
// ------------------------------------------- 2. same time step, trigger first
#10;
`uvm_info("TAV_2", "-> e2, then the waiters start in the same time step", UVM_LOW)
->e2;
fork
tav_at("TAV_2", e2);
tav_wt("TAV_2", e2);
join
// ------------------------------------------- 3. waiter one time step late
#10;
`uvm_info("TAV_3", "-> e3", UVM_LOW)
->e3;
#1 `uvm_info("TAV_3", "waiters start 1 ns after the trigger", UVM_LOW)
fork
tav_at("TAV_3", e3);
tav_wt("TAV_3", e3);
join
// ------------------------------------------- 4. nonblocking trigger
#10;
`uvm_info("TAV_4", "->> e4, then @(e4) starts in the same time step", UVM_LOW)
->>e4;
tav_at("TAV_4", e4);
// ------------------------------------------- 5. wait(triggered) in a loop
#10;
->e5;
n = 0;
repeat (1000) begin
wait(e5.triggered);
n++;
end
`uvm_info("TAV_5", $sformatf("loop passed wait(e5.triggered) %0d times, time did not move", n), UVM_LOW)
// ------------------------------------------- 6. uvm_event
#10;
ue = new("ue");
`uvm_info("TAV_6", "ue.trigger(), then wait 1 ns", UVM_LOW)
ue.trigger();
#1;
fork
begin ue.wait_trigger(); `uvm_info("TAV_6", "wait_trigger() returned", UVM_LOW) end
#5 `uvm_info("TAV_6", "wait_trigger() still waiting after 5 ns, giving up", UVM_LOW)
join_any
disable fork;
fork
begin ue.wait_ptrigger(); `uvm_info("TAV_6", "wait_ptrigger() returned", UVM_LOW) end
#5 `uvm_info("TAV_6", "wait_ptrigger() still waiting after 5 ns, giving up", UVM_LOW)
join_any
disable fork;
`uvm_info("TAV_6", $sformatf("is_on() = %0d before reset()", ue.is_on()), UVM_LOW)
ue.reset();
fork
begin ue.wait_ptrigger(); `uvm_info("TAV_6", "after reset(): wait_ptrigger() returned", UVM_LOW) end
#5 `uvm_info("TAV_6", "after reset(): wait_ptrigger() still waiting after 5 ns, giving up", UVM_LOW)
join_any
disable fork;
fork
begin
ue.wait_trigger_data(data);
`uvm_info("TAV_6", $sformatf("wait_trigger_data() got an object named \"%s\"", data.get_name()), UVM_LOW)
end
begin
tav_msg payload = new("tav_payload");
#2 ue.trigger(payload);
end
join
// ------------------------------------------- 7. two handles, one event
#10;
e7b = e7a; // e7b now refers to the same event
fork
tav_at("TAV_7", e7b);
begin #1 `uvm_info("TAV_7", "-> e7a (the waiter is on e7b)", UVM_LOW) ->e7a; end
join
// ------------------------------------------- 8. uvm_event: same step, and wait_on()
#10;
ue = new("ue8");
ue.trigger();
fork
begin ue.wait_ptrigger(); `uvm_info("TAV_8", "same time step: wait_ptrigger() returned", UVM_LOW) end
#5 `uvm_info("TAV_8", "same time step: wait_ptrigger() still waiting after 5 ns, giving up", UVM_LOW)
join_any
disable fork;
ue = new("ue8b");
ue.trigger();
#1;
fork
begin ue.wait_on(); `uvm_info("TAV_8", "1 ns later: wait_on() returned", UVM_LOW) end
#5 `uvm_info("TAV_8", "1 ns later: wait_on() still waiting after 5 ns, giving up", UVM_LOW)
join_any
disable fork;
// ------------------------------------------- 9. wait(expression) vs @(expression)
#10;
ready = 1; // already true when the waiters start
fork
begin
wait (ready == 1);
`uvm_info("TAV_9", "wait(ready == 1) returned at once, ready was already 1", UVM_LOW)
end
begin
fork
begin @(ready); `uvm_info("TAV_9", "@(ready) woke up", UVM_LOW) end
#5 `uvm_info("TAV_9", "@(ready) still waiting after 5 ns, giving up", UVM_LOW)
join_any
disable fork;
end
join
// ------------------------------------------- 10. wait fork
#10;
fork
#3 `uvm_info("TAV_10", "child A done", UVM_LOW)
#7 `uvm_info("TAV_10", "child B done", UVM_LOW)
join_none
`uvm_info("TAV_10", "parent: join_none returned, now wait fork", UVM_LOW)
wait fork;
`uvm_info("TAV_10", "parent: wait fork returned", UVM_LOW)
phase.drop_objection(this);
endtask
endclass
endpackage
module tav_top;
import uvm_pkg::*;
import tav_ev_pkg::*;
initial run_test("tav_ev_test");
endmodule
What VCS printed
VCS X-2025.06-SP1 with UVM 1.2. The run ended at 134 ns with UVM_ERROR : 0 and UVM_WARNING : 0. Every TAV line is shown in its part above, with the UVM_INFO testbench.sv(NN) prefix trimmed.
Notice that the missed events in parts 2, 3 and 6 left no error at all. A missed event never reports itself; only your timeout does.
Common mistakes (and the fix for each)
1. @(ev) when the trigger can come first. In part 2 it missed a trigger in the same time step. Fix: wait(ev.triggered), or ->> on the triggering side.
2. Trusting wait(ev.triggered) across time. In part 3 a waiter 1 ns late missed it. Fix: a flag with wait(flag), or uvm_event::wait_on().
3. Using wait_ptrigger() as a memory. In part 6 it missed a trigger from 1 ns earlier while is_on() was 1. Fix: wait_on().
4. wait(ev.triggered) in a forever loop. In part 5 it passed 1000 times with time standing still. Fix: put a time-consuming wait, like @(posedge clk), in the loop.
5. @(signal) for a level. In part 9 @(ready) waited for a change while ready was already 1. Fix: wait(ready == 1).
Where AI helps, and where it doesn’t
An AI assistant is good at spotting a @(ev) that can lose a race, and at turning a hung wait into a fork with a timeout. It’s also quick at explaining which region of the time step an event fires in.
Where it trips is wait_ptrigger(): an assistant will happily tell you it remembers a trigger across time, and the run and the UVM source show it doesn’t. That’s why every claim here comes from a log line.
Practice challenge
Add a part 11 where a driver task triggers a uvm_event at a random time between 0 and 10 ns, and a monitor task starts waiting at another random time in the same range. Make the monitor never hang, whichever one starts first.
FAQ
What is the difference between @(ev) and wait(ev.triggered)? @(ev) waits for the next trigger after it starts. wait(ev.triggered) also returns for a trigger earlier in the same time step.
Why does @(ev) miss an event? If the trigger happens before @(ev) starts waiting, even in the same time step, there’s no later trigger for it to see. In my run it gave up 5 ns later.
Does wait(ev.triggered) work across time steps? No. A waiter that started 1 ns after the trigger missed it in my run.
How does the wait statement work in SystemVerilog? wait(expression) blocks until the expression is true, and returns at once if it already is. It’s level-sensitive, unlike @.
What does wait fork do? It blocks until every child process started by the current process has finished. In my run it returned when the slower of two join_none children finished.
What is the difference between wait_trigger(), wait_ptrigger() and wait_on() in uvm_event? wait_trigger() waits for the next trigger. wait_ptrigger() also catches a trigger in the same time step. wait_on() returns at once if the event was triggered at any time since the last reset().
What does ->> do? It’s a nonblocking trigger: the event fires later in the same time step, so an @(ev) that starts in that step still catches it.
References
- IEEE 1800-2023, SystemVerilog standard: clause 9.4 (procedural timing controls, including event control and wait), clause 9.6 (process control, including wait fork) and clause 15.5 (named events).
- IEEE 1800.2, UVM class reference: uvm_event (wait_on, wait_trigger, wait_ptrigger).
Keep learning
Events usually live inside a fork, so the flavours of fork join is the natural next read, especially join_none and disable fork. To pass a permission or a value between the same processes, see the semaphore in SystemVerilog and the mailbox in SystemVerilog.
For where events sit in a full bench, read the UVM testbench architecture. There’s more in the SystemVerilog category and the interview questions.
Part of the learning path SystemVerilog for verification
