Semaphores with multiple keys

In which case task abc_2 will execute

semaphore sem = new(2);
task abc_1();
sem.get(2)
  // DO
sem.put(1)
endtask

task abc_2();
sem.get(1)
  // DO
sem.put(1)
endtask

CASE 1:

initial fork 
abc_1();
abc_1();
abc_1();
abc_2();
join

CASE 2:

initial begin 
abc_1();
abc_1();
abc_1();
abc_2();
end

SystemVerilog guarantees that abc_2 will not execute in CASE 2 because there is a defined execution ordering of statements within a begin/end block, and it will get stuck during the second call to abc_1.

However, there is no defined execution ordering of statements within a fork/join block. You might be able to deduce the particular ordering of a implementation, but you cannot rely on that ordering. An implementation that chooses to first execute the last statement as it appears in the source will call abc_2.

In reply to dave_59:

Thanks…I understood…

In reply to dave_59:

Hi Dave,

what do you mean for implementation?

In reply to dariof:

I mean the code that executes as a result of compiling your source descriptions. The implementation can vary by tool version, platform and OS that where the code executes.

In reply to dave_59:

Ok, thanks a lot for your support.