Jump to content
flasher07

Help regarding fork_join usage

Recommended Posts

Hi ,

 

Please help me the following code, 

module fork_join_any_process();

  int me[3];
  
task automatic print_value;
  input [7:0] value;
  input [7:0] delay;
  begin
    $display("Waiting Passed value %d",value);
    #(delay) $display("@%g Passed Value %d Delay %d",
      $time, value, delay);
  end
endtask

initial begin
  me[0] = 1;
  me[1] = 2;
  me[2] = 3;
  repeat(5) begin
  fork 
    foreach(me[i]) 
      fork automatic int id = me[i]; print_value (10+id,id); join_none
    foreach(me[i]) 
      fork automatic int id = me[i]; print_value (20+id,id); join_none
  //  wait fork;
  join_any
  disable fork;
    $display(" Disable Fork ");
//    for (int i = 0 ; i < 3 ;i++) begin
//      fork
//        print_value (10+i,7);
//        print_value (20+i,7);
//        print_value (30+i,7);        
//      join_any
//      if ( i < 2 ) begin
//        print_value (50+i,7);
//        print_value (60+i,7);
//      end     
//    end
  end
  $display("@%g Came out of fork-join", $time);
  #20 $finish;
end

endmodule

Expecting the output as:

Waiting Passed value  11
Waiting Passed value  12
Waiting Passed value  13
Waiting Passed value  21
Waiting Passed value  22
Waiting Passed value  23
@1 Passed Value  11 Delay   1
Disable fork
Waiting Passed value  11
Waiting Passed value  12
Waiting Passed value  13
Waiting Passed value  21
Waiting Passed value  22
Waiting Passed value  23
@1 Passed Value  11 Delay   1

 

 

But unable to get that, Please help me with this.

 

Thanks a lot !! :)

 

Share this post


Link to post
Share on other sites

You use fork/join_any statements when you want to create a number of time consuming processes and block waiting for one of them to finish. You create two processes, but they do not bloc - the finish immediately because they have fork/join_none statements in them . What you probably meant was something like

 

initial begin
   me[0] = 1;
   me[1] = 2;
   me[2] = 3;
   repeat(5) begin : repeat_loop
      fork begin : b1
         foreach(me)
           fork automatic int id = me; print_value (10+id,id); join_none
        wait fork;
      end : b1
      begin :b2
          foreach(me)
            fork automatic int id = me; print_value (20+id,id); join_none
         wait fork;
       end : b2
      join_any
      disable fork;
      $display(" Disable Fork ");
      end :repeat_loop
   $display("@%g Came out of fork-join", $time);
   #20 $finish;
end // initial begin

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×