Can we use repeat loop inside fork join_any?

fork 
  repeat(8)begin
  thread1();
  thread2();
  end
join_any

In reply to Abi aadhira:

It can definitely be used. Why do you think it cannot be used ?

The simplest thing to do would be to try it out.


module test();
  
  initial begin
    fork
      repeat(2)begin
        thread1();
        thread2();
      end
    join_any
    $display("Out of fork");
  end

  
endmodule

task thread1();
  #1;
  $display("Thread 1 : %t", $time);
endtask

task thread2();
  #3;
  $display("Thread 2 : %t", $time);
endtask

Output :
xcelium> run
Thread 1 : 1
Thread 2 : 4
Thread 1 : 5
Thread 2 : 8
Out of fork
xmsim: *W,RNQUIE: Simulation is complete.
xcelium> exit

In reply to Abi aadhira:

I dont see any problem with the code.
Inside the repeat loop the threads are started sequentially. So thread1 will finish before thread2 starts and thread2 finishes before the thread1 of the next iteration starts.
Hope this helps.

This may be a more interesting exercsise because the threads are started in parallel
and the 8 iterations of the repeat loop will start simultaneously.


     repeat(8)  begin
        fork 
           thread1();
           thread2();
        join_any
  end


Logie Ramachandran.

In reply to KillSteal:

Thank you for your response

In reply to logie:

Thank you logie