Foreach fork ... join_none

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

In reply to mlsxdx:

Where is the disable fork?

In reply to yaswanth021:

In reply to mlsxdx:
Where is the disable fork?

I prefer to use process::kill(). It is in the class proc_manager, a method called remove_proc(bit ch).

In reply to mlsxdx:

There are many more differences than just for versus foreach. Specifically, the fork/join_none used with the foreach loop spawns three processes for each iteration. The statement
proc_mgr.proc_pool[idx][0] = process::self();
is in an isolated process.

In reply to dave_59:

Thanks for your comments, dave.

I have one question on that:
1.How can user know how many threads are spawned for sure? In this case, is there a way by adding print information to identify foreach … fork/join_none spawns three processes?

  • M

In reply to mlsxdx:

This is infomration that an interactive debugging tool might provide.