In SystemVerilog I need to wait for some threads that have been executed inside a fork join_none structure to finish. But there is another process inside another fork join_none structure that will never end.
My code looks like this:
fork
process_that_will_never_end();
join_none
fork
for(int i = 0; i < 40; i++) begin
fork
process_that_must_end(i);
join_none
end
join
The fork join containing the for loop has no effect (which is what I expected). I thought about using a "wait fork" at the end but this will also wait for process_that_will_never_end(), so it won't work.
Is there any way to wait only for all the process_that_must_end() threads to finish?
You almost had it. You just need to move the scope of the begin/end
to outside the for loop. Then the wait fork
only applies to the children of the second fork
.
fork : first_fork
process_that_will_never_end();
join_none
fork begin : second_fork
for(int i = 0; i < 40; i++)
fork : third_forks
automatic int k = i;
process_that_must_end(k);
join_none
wait fork;
end join