User guide
24-179
SystemVerilog Testbench Constructs
#5 sem1.put(1);
$display("inital2 returns 1 key at %0t",$time);
end
endprogram
In the revised initial2, at simulation time 5, the try_get method
checks to see if there are two keys in sem1. There aren’t, because
initial1 took one. At time 10 the put method “returns” a key to sem1.
Actually the get and put methods only decrement and increment a
counter for the keys, there are no keys themselves, so initial2 can
increment the key count without having previously decrementing this
count.
The $display system tasks display the following:
initial1 takes 1 key at 1
initial1 returns 1 key at 7
initial1 takes 1 key at 8
inital2 returns 1 key at 10
Semaphore Methods
Semaphores have the following built-in methods:
new (number_of_keys)
You use this method with the semaphore keyword. It specifies
the initial number of keys in the semaphore.
put(number_of_keys)
Increments the number of keys in the semaphore.