User guide

24-178
SystemVerilog Testbench Constructs
The program has a semaphore named sem1 that starts with two keys,
as specified with the semaphore keyword and new() method.
If it were not for initial2, initial1 would do the following:
1. Take a key at simulation time 1 (using the get method).
2. Return a key at time 7 (using the put method).
3. Take a key again at time 8 (using the get method).
If it were not for initial1, initial2 would do the following:
1. Take two keys at simulation time 5 (using the get method).
2. Return one key at time 10 (using the put method).
However both initial blocks contend for a limited number of keys that
they need in order to finish executing, in taking keys that the other
needs, they interrupt each other’s processing. The $display system
tasks display the following:
initial1 takes 1 key at 1
initial1 returns 1 key at 7
inital2 takes 2 keys at 7
inital2 returns 1 key at 12
initial1 takes 1 key at 12
The initial block initial2 could be rewritten to use the try_get method
to see if a certain number of keys are available, for example:
initial
begin:initial2
#5 if(sem1.try_get(2))
begin
sem1.get(2);
$display("inital2 takes 2 keys at %0t",$time);
end