Hi,
Can someone help me to understand why the foreach fork … join_none does not work as expected?
However, when the foreach loop is changed to for … loop, it works.
Basically, after killing the fork process, it is expected that no more print info. However, the foreach fork … join_none seems to have active processes going on. What is the problem here?
foreach fork … join_none
foreach(arr[i]) fork : fork_proc
automatic bit[1:0] idx = i;
proc_mgr.alloc_proc(idx,1);
proc_mgr.proc_pool[idx][0] = process::self();
forever begin
@(posedge vif.clk) begin
if(vif.cnt[idx] > 0 && vif.cnt[idx]%2 == idx) begin
$display($time,, $sformatf("Thread%0d detect cnt[%0d]:%0d modulo 2 is %0d.",idx,idx,vif.cnt[idx],idx));
for(int j=0; j<2; j++) begin
$display($time,,"Thread%0d loc[%0d][%0d]:%0d",idx,idx,j,loc[idx][j]);
end
end
end
end
join_none
for fork … join_none
for(int i=0; i<2; i++) begin
automatic bit idx = i;
proc_mgr.alloc_proc(i,1);
fork begin
proc_mgr.proc_pool[idx][0] = process::self();
forever begin
@(posedge vif.clk);
if(vif.cnt[idx] > 0 && vif.cnt[idx]%2 == idx) begin
$display($time,, $sformatf("Thread%0d detect cnt[%0d]:%0d modulo 2 is %0d.",idx,idx,vif.cnt[idx],idx));
end
end
end
join_none
end
The running code is at: foreach within fork ... join_none - EDA Playground