Jump to content

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 !! :)

 

Link to comment
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

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...