In fork join, a process that will be executed first if all three processes have a random delay


module fork_join;
  
  bit[3:0] vari1=$random;
  bit[3:0] vari2=$random;
  bit[3:0] vari3=$random;
  
  
  semaphore se;
  
  
  //in
  
  initial begin
    se=new();
    if(se ==1)
     get.se(1);


    $display("-----------------------------------------------------------------");
       
    
    fork
      //-------------------
      //Process-1
      //-------------------
      begin
        
        
        #vari1;
        $display($time,"\tProcess-1 Finished");
        //se.put();
      end
      //-------------------
      //Process-2
      //-------------------
      begin
        
        #vari2;
        $display($time,"\tProcess-2 Finished");
        
        //se.put();
      end
      begin
        
        #vari3;
        $display($time,"\tProcess-3 Finished");
        //se.put();
      end
    join
    
     
 end  
endmodule

i wanted to know, which process get executed first in fork join, if i am passing random delay in all process.

thanks,
muku

In reply to muku_383:

In your example, all three processes begin executing at the same time 0 in an indeterminate order. They will end in the order determined by the random values. There is a 0.4% chance that the chosen values that are all the same; in that case, the ending order will be indeterminate.

BTW, I recommend replacing all use of $random with $urandom to get the benefits of SystemVerilog’s seed management and random stability.