Semaphore put method question

hI

I have a question regarding semaphore.

code


module semaphore_ex;
  semaphore sema; //declaring semaphore sema
 
  initial begin
    sema=new(4); //creating sema with '4' keys 
    fork
      display("Process 1"); //process-1
      display("Process 2"); //process-2
      display("Process 3"); //process-3
      display("Process 4"); //process-4
    join
  end
  task automatic display(string str);
  sema.get();
  $display("%s",str);
  sema.put();
  sema.put();
  endtask

endmodule


My question is if we use put two times, does the task get stuck because by definition put method is blocking or it actually increases the number of keys to 2 when you use an extra put and it does not behave as blocking?

In reply to Himanshu Madnani:

put() is a function, it cannot block.

Your example constructs the semaphore with four keys. Each process grabs one key and returns two keys. At the end, there are eight keys and nothing ever blocked.