User guide

24-177
SystemVerilog Testbench Constructs
Interprocess Synchronization and Communication
Semaphores
SystemVerilog semaphores are not signal devices. They are buckets
that contain keys, where competing resources, such as different initial
blocks in a program, require keys from the bucket to continue
processing.
program prog;
semaphore sem1 = new(2);
initial
begin:initial1
#1 sem1.get(1);
$display("initial1 takes 1 key at %0t", $time);
#6 sem1.put(1);
$display("initial1 returns 1 key at %0t",$time);
#1 sem1.get(1);
$display("initial1 takes 1 key at %0t", $time);
end
initial
begin:initial2
#5 sem1.get(2);
$display(" inital2 takes 2 keys at %0t",$time);
#5 sem1.put(1);
$display(" inital2 returns 1 key at %0t",$time);
end
endprogram
In this program there are two initial blocks, labeled by the label on
their begin-end blocks, initial1 and intital2.