[SV]SystemVerilog進程控制詳解及案例分析 ---wait fork/disable fork

                    SystemVerilog進程控制詳解及案例分析

                                                    ---wait fork/disable fork

 

       前言:之前我們講過SystemVerilog進程之fork-join專題(Link),本文著重分析一下SV中進程的控制。

 

  • 目錄

一、進程控制

 1.1、wait-fork

 1.2、 Example-1: fork join_none

 1.3、Example-2:  wait fork

 1.4、disable-fork

 1.5、Example-3: disable-fork


一、進程控制

 1.1、wait-fork

  • wait fork:导致进程阻塞,直到从fork块启动的所有进程完成为止(causes the process to block until the completion of all processes started from fork blocks.) 

    wait fork example ,In the below example:

  • After the completion of Process-1 (i.e, after 5ns) fork-join_any will get unblocked,
  • The $finish() will get called and it ends the  simulation. 
  • The simulation will get ended in the middle of the execution of process-2, this can be avoided with the use of wait-fork. The problem in this example is overcome in example-2 with the use of wait fork

 

 1.2、 Example-1: fork join_none

module wait_fork;
 
  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("-----------------------------------------------------------------");
$finish; //ends the simulation
  
  end
endmodule
  • Simulator output: 
-----------------------------------------------------------------
0 Process-1 Started
0 Process-2 Started
5 Process-1 Finished
-----------------------------------------------------------------

 

 1.3、Example-2:  wait fork

  • In the below example, wait fork will wait for the completion of the second thread in the fork-join_any.
  • for better understanding compare the result  of Example-1 and Example-2.
module wait_fork;
 
  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
    wait fork; //waiting for the completion of active fork threads
     
    $display("-----------------------------------------------------------------");
    $finish; //ends the simulation
  end
endmodule
  • Simulator output: 
-----------------------------------------------------------------
0 Process-1 Started
0 Process-2 Started
5 Process-1 Finished
20 Process-2 Finished
-----------------------------------------------------------------

 

  1.4、disable-fork

  • disable fork导致进程杀死/终止从fork块启动的所有活动进程(causes the process to kill/terminate all the active processes started from fork blocks.
  • disable fork會殺死當前進程以及他的所有子進程
  • disable fork example,In the below example:
  • On execution of the disable fork, all the active process will get terminated. 
  • Process-2 of fork-1,Process-1, and Process-2 of fork-2 will get terminated.
module disable_fork;
 
  initial begin
    $display("-----------------------------------------------------------------");
 
    //fork-1
    fork
      //Process-1
      begin
        $display($time,"\tProcess-1 of fork-1 Started");
        #5;
        $display($time,"\tProcess-1 of fork-1 Finished");
      end
       
      //Process-2
      begin
        $display($time,"\tProcess-2 of fork-1 Started");
        #20;
        $display($time,"\tProcess-2 of fork-1 Finished");
      end
    join_any
 
    //fork-2
    fork
      //Process-1
      begin
        $display($time,"\tProcess-1 of fork-2 Started");
        #5;
        $display($time,"\tProcess-1 of fork-2 Finished");
      end
      //Process-2
      begin
        $display($time,"\tProcess-2 of fork-2 Started");
        #20;
        $display($time,"\tProcess-2 of fork-2 Finished");
      end
    join_none   
 
    disable fork;
     
    $display("-----------------------------------------------------------------");
      $display($time,"\tAfter disable-fork");
    $display("-----------------------------------------------------------------");
  end
endmodule
  • Simulator output: 
-----------------------------------------------------------------
0 Process-1 of fork-1 Started
0 Process-2 of fork-1 Started
5 Process-1 of fork-1 Finished
-----------------------------------------------------------------
5 After disable-fork
-----------------------------------------------------------------

 

1.5、Example-3: disable-fork

  •  In the below example, sub_process started from process-2 will get terminated during the execution of disable fork.
module disable_fork;
  initial begin
    $display("-----------------------------------------------------------------");
 
    fork
      //Process-1
      begin
        $display($time,"\tProcess-1 of fork-1 Started");
        #5;
        $display($time,"\tProcess-1 of fork-1 Finished");
      end
      //Process-2
      begin
        sub_process();
      end
    join_any 
   
    disable fork;
   
    $display("-----------------------------------------------------------------");
    $display($time,"\tAfter disable-fork");
    $display("-----------------------------------------------------------------");
  end
  //Sub-Process
  task sub_process;
    $display($time,"\tSub-Process Started");
    #10;
    $display($time,"\tSub-Process Finished");
  endtask  
endmodule
  • Simulator output: 
-----------------------------------------------------------------
0 Process-1 of fork-1 Started
0 Sub-Process Started
5 Process-1 of fork-1 Finished
-----------------------------------------------------------------
5 After disable-fork
-----------------------------------------------------------------

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

元直数字电路验证

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

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

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

打赏作者

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

抵扣说明:

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

余额充值