[SV]SystemVerilog進程之fork join专题详解及案例分析

SystemVerilog進程之fork...join专题详解及案例分析 

  • 目錄

一、fork-join

 1.1、fork join example,  

二、fork-join_any

 2.1、fork join any example,

三、fork-join_none

  3.1、fork join_none example,


一、fork-join

  • Fork-Join will start all the processes inside it parallel and wait for the completion of all the processes.

 1.1、fork join example,  

  • In below example,fork block will be blocked until the completion of process-1 and Process-2. 
  • Both process-1 and Process-2 will start at the same time,
  • Process-1 will finish at 5ns and Process-2 will finish at 20ns.
  • fork-join will be unblocked at 20ns.
module fork_join;
 
  initial begin
    $display("-----------------------------------------------------------------");
    fork
      //-------------------
      //Process-1
      //-------------------
      begin
        $display($time,"\tProcess-1 Started");
        #5;
        $display($time,"\tProcess-1 Finished");
      end
 
      //-------------------
      //Process-2
      //-------------------
      begin
        $display($time,"\tProcess-2 Started");
        #20;
        $display($time,"\tProcess-2 Finished");
      end
    join
 
    $display($time,"\tOutside Fork-Join");
    $display("-----------------------------------------------------------------");
    $finish;
  end
endmodule
  • Simulator output:  
-----------------------------------------------------------------
0 Process-1 Started
0 Process-2 Startedt
5 Process-1 Finished
20 Process-2 Finished
20 Outside Fork-Join
-----------------------------------------------------------------

 

二、fork-join_any

  • Fork-Join_any will be unblocked after the completion of any of the Processes.

 2.1、fork join any example,

  • In the below example,fork block will be blocked until the completion of any of the Process Process-1 or Process-2. 
  • Both Process-1 and Process-2 will start at the same time, Process-1 will finish at 5ns and Process-2 will finish at 20ns. 
  • fork-join_any will be unblocked at 5ns.
module fork_join;
  initial begin
    $display("-----------------------------------------------------------------");
    fork
      //Process-1
      begin
        $display($time,"\tProcess-1 Started");
        #5;
        $display($time,"\tProcess-1 Finished");
      end
 
      //Process-2
      begin
        $display($time,"\tProcess-2 Started");
        #20;
        $display($time,"\tProcess-2 Finished");
      end
    join_any
 
    $display($time,"\tOutside Fork-Join");
    $display("-----------------------------------------------------------------");
  end
endmodule
  • Simulator output: 
--------------------------------------------------------
0 Thread-1 Started
0 Thread-2 Started
5 Thread-1 Finished
5 Outside Fork-Join
-----------------------------------------------------------------
20 Process-2 Finished

三、fork-join_none

  • Processes inside the fork-join_none block will be started at the same time, fork   block will not wait for the completion of the Process inside the fork-join_none.

  3.1、fork join_none example,

  • In the below example, The fork will start Process-1 and Process-2 at the same time, and it will come out of the block. Process-1 and Process-2 will be executed until the completion.
module fork_join_none;
  initial begin
    $display("-----------------------------------------------------------------");
 
    fork
      //Process-1
      begin
        $display($time,"\tProcess-1 Started");
        #5;
        $display($time,"\tProcess-1 Finished");
      end
      //Process-2
      begin
        $display($time,"\tProcess-2 Startedt");
        #20;
        $display($time,"\tProcess-2 Finished");
      end
    join_none
  
    $display($time,"\tOutside Fork-Join_none");
    $display("-----------------------------------------------------------------");
  end
endmodule
  • Simulator output: 
-----------------------------------------------------------------
0 Outside Fork-Join_none
-----------------------------------------------------------------
0 Process-1 Started
0 Process-2 Startedt
5 Process-1 Finished
20 Process-2 Finished

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

元直数字电路验证

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值