Threads, Events, Mailboxes, and Semaphores
Run several testbench activities in parallel and choose the right synchronization mechanism.
Several activities at once
A testbench often needs to generate commands, monitor responses, and enforce a timeout in parallel. fork...join launches several threads.
fork
drive_requests();
monitor_responses();
watch_timeout();
joinjoin waits for every thread. join_any resumes after the first finishes. join_none resumes immediately and leaves all branches running. With join_any, the remaining branches often need a clean stop such as disable fork so a timeout or driver does not outlive the test.
Automatic local variables prevent loop iterations from unintentionally sharing one value between threads.
for (int port = 0; port < 4; port++) begin
automatic int selected_port