Write code to execute task A in parallel 10 times, and call task B only after task A has finished executing 10 times

In reply to ben@SystemVerilog.us:

I believe you can use wait fork instead of creating a vector, just keep in mind that specifying wait fork causes the calling process to block until all its immediate child subprocesses have completed, as described in the LRM section 9.6.1 Wait fork statement


   repeat(10) begin // this could be a for loop with the automatic k = i
      fork
        A(); //call A
      join_none
   end
   wait fork; // wait for all spawned tasks to complete
   B(); // execute B

For example

module m();
 
  task automatic A();
    int unsigned w; 
    w = $urandom_range(1, 20);
    #w;
    $display("Task A. w= %0d Time = %0t", w, $realtime);
  endtask
 
  task automatic B();
    int unsigned w; 
    w = $urandom_range(1, 10);
    #w;
    $display("Task B. w = %0d Time = %0t", w, $realtime);
  endtask
 

  task automatic t();
    repeat(10) begin
      fork
        A();
      join_none
    end
    wait fork;
    B();
  endtask
 
  initial begin
    t();
  end
 
endmodule

# KERNEL: Task A. w= 1 Time = 1
# KERNEL: Task A. w= 2 Time = 2
# KERNEL: Task A. w= 3 Time = 3
# KERNEL: Task A. w= 5 Time = 5
# KERNEL: Task A. w= 5 Time = 5
# KERNEL: Task A. w= 10 Time = 10
# KERNEL: Task A. w= 12 Time = 12
# KERNEL: Task A. w= 14 Time = 14
# KERNEL: Task A. w= 18 Time = 18
# KERNEL: Task A. w= 18 Time = 18
# KERNEL: Task B. w = 9 Time = 27

If you require a fine control of each process you can look in to the LRM section 9.7 Fine-grain process control

HTH,
-R