Sequences started in parallel and how to use fork join_any if the number of sequences is varied?

Hi,

I have a question for using sequences.start in parallel.
I would like to make task such that only one sequence should complete and others should be stopped. I’ve tried to use fork join_any but the number of sequences is changed. And I don’t know how to change the code.

Is it possible to write with variable for the number of sequences? If it is, can you give me any hints?

task test1(int n)
..
fork
begin
 seq[1].start(null);
 seq[2].start(null);
 seq[3].start(null);
...
 seq[n].start(null);
end
join_any;

disable fork;
..
endtask;

Thank you,
Seunghyun Lee

In reply to dv_lee86:

You can put this in a fork join_none loop and trigger an event when one of the sequences finishes.

task test1(int n);
event done;
...
  fork // isolation for disable fork if needed 
    begin :isolation_thread
      for (int int i=1;i<=n;i++)
        fork
          int j = i;
          begin
            seq[j].start(null);
            ->done;
          end
        join_none
      @done
      disable fork;
    end : isolation_thread
  join
..
endtask;

In reply to dave_59:

Hi,

Thank you for answer. That’s exactly what I wanted. I have one question for the code. Instead of using seq[i].start, can you help me understand why int j is used for seq[j].start?

Thank you,
Seunghyun Lee

In reply to dv_lee86:

See Why loop variable should not be used in FORK JOIN_NONE | Verification Academy

In reply to dave_59:

Thank you for the link. Now I understood. Thank you for help.