首页 > 其他分享 >SystemVerilog -- 3.5 Wait fork

SystemVerilog -- 3.5 Wait fork

时间:2024-05-12 22:31:29浏览次数:17  
标签:fork 20 0t -- 3.5 time ns display

Wait fork

wait fork允许 main thread 等待,直到所有 forked threads 都结束。这在 main thread 必须生成多个 threads 并在等待所有 threads 完成之前执行某些功能的情况下非常有用。

Example

我们将使用上一篇文章中相同的示例,其中 3 个 threads 并行启动,main thread 等待其中一个 thread 完成。main thread 恢复后,让我们等到所有 forked threads 都完成。

module tb_top;
  initial begin
    // Fork off 3 sub-threads in parallel and the currently executing main thread will finish when any of the 3 sub-threads have finished.
    fork
      // Thread1 : Will finish first at time 40ns
      #40 $display ("[%0t ns] Show #40 $display statement", $time);

      // Thread2 : Will finish at time 70ns
      begin
        #20 $display ("[%0t ns] Show #20 $display statement", $time);
        #50 $display ("[%0t ns] Show #50 $display statement", $time);
      end

      // Thread3 : Will finish at time 60ns
      #60 $display ("[%0t ns] TIMEOUT", $time);
    join_any

    // Display as soon as the fork is done
    $display ("[%0t ns] Fork join is done, wait fork to end", $time);

    // Wait until all forked processes are over and display
    wait fork;
    $display ("[%0t ns] Fork join is over", $time);
  end
endmdoule

模拟日志

ncsim> run
[20 ns] Show #20 $display statement
[40 ns] Show #40 $display statement
[40 ns] Fork join is done, wait fork to end
[60 ns] TIMEOUT
[70 ns] Show #50 $display statement
[70 ns] Fork join is over
ncsim: *W,RNQUIE: Simulation is complete.

Dose wait fork wait until all processes are over ?

为了了解它在这种情况下的行为,让我们在forked two threads 并等待 forked 完成。

module tb_top;
  initial begin
    // Fork off 3 sub-threads in parallel and the currently executing main thread will finish when any of the 3 sub-threads have finished.
    fork
      // Thread1 : Will finish first at time 40ns
      #40 $display ("[%0t ns] Show #40 $display statement", $time);

      // Thread2 : Will finish at time 70ns
      begin
        #20 $display ("[%0t ns] Show #20 $display statement", $time);
        #50 $display ("[%0t ns] Show #50 $display statement", $time);
      end

      // Thread3 : Will finish at time 60ns
      #60 $display ("[%0t ns] TIMEOUT", $time);
    join_any

    // Display as soon as the fork is done
    $display ("[%0t ns] Fork join is done, wait fork to end", $time);

    // Fork two more processes
    fork
      #10 $display ("[%0t ns] Wait for 10", $time);
      #20 $display ("[%0t ns] Wait for 20", $time);
    join_any

    // Wait until all forked processes are over and display
    wait fork;
    $display ("[%0t ns] Fork join is over", $time);
  end
endmdoule

模拟日志

ncsim> run
[20 ns] Show #20 $display statement
[40 ns] Show #40 $display statement
[40 ns] Fork join is done, wait fork to end
[50 ns] Wait for 10
[60 ns] TIMEOUT
[60 ns] Wait for 20
[70 ns] Fork join is over
ncsim: *W,RNQUIE: Simulation is complete.

标签:fork,20,0t,--,3.5,time,ns,display
From: https://www.cnblogs.com/sys-123456/p/18188251

相关文章

  • 音乐格式转换:java代码实现
    1packageutil;23importws.schild.jave.*;4importjava.io.File;56/*7音乐格式转换8<dependency>9<groupId>ws.schild</groupId>10<artifactId>jave-core</artifactId>11<version>2.4.4</versi......
  • Atcoder ABC 353 全题解
    最近看的人好少……都快不想写了……你们的支持就是我创作的最大动力!AB%你CDE题意:有一个一个一个函数,把函数两两配对式求值,求这些值最后的总和C考虑将所有的和减去$10^8$出现的次数。将整个数组排序,然后进行二分,求第一个与这个数的和$\ge10^8$的位置,然后与这个数......
  • laravel,webman,hyperf,thinkphp推荐哪一个?
    2024年5月11日14:11:45laravelwebmanhyperfthinkphp流行程度国内流行,欧洲特别是法国,美国,日本很多使用主要在国内流行,少量国外使用主要国内流行,少量国外使用国内流行,国外俄罗斯有使用性能fpm多进程模式,性能一般,偏差同步阻塞多进程模式,性能很好web第一梯队协......
  • Spark - [03] RDD概述
    RDD,分布式数据集,是Spark中最基本的数据抽象。 一、什么是RDDRDD(ResilientDistributedDataset)叫做分布式数据集,是Spark中最基本的数据抽象。代码中是一个抽象类,它代表一个不可变、可分区、里面的元素可并行计算的集合。  二、RDD的属性①一组分区(Partition),即数据......
  • 原型设计工具
    2252118顾佳豪AxureRP主要特点:交互设计:支持复杂的动态交互和逻辑表达。文档输出:可以输出规范的产品需求文档。协作功能:支持团队协作和项目管理。高保真原型:创建接近最终产品的高保真原型。使用方法:使用库面板中的元件创建页面布局。利用交互功能定义元件行为......
  • 45_jump Game II 跳跃游戏II
    45_jumpGameII跳跃游戏II问题描述链接:https://leetcode.com/problems/jump-game-ii/description/Youaregivena0-indexedarrayofintegersnumsoflengthn.Youareinitiallypositionedatnums[0].Eachelementnums[i]representsthemaximumlengthofafo......
  • 生命周期---Vue2&Vue3
    生命周期---Vue2&Vue3简单理解为:组件从创建到被销毁的一个过程,就相当于人的一生,从出生到死亡的一个过程。组件的生命周期也称生命周期、生命周期函数、生命周期钩子生命周期在特定的时刻会调用特定的函数生命周期分为四个阶段,每个阶段都有两个钩子,现只讨论这八个钩子V......
  • Comfy UI 绘画使用(3):详细了解Confyui工作流
    目录前言相关视频作者示例下载高清修复hiresfix_latent_workflow二次改造为高清修复工作流hiresfix_esrgan_workflow:低修改高清工作流最好的放大方案,解决爆显存局部重绘绘制蒙版小幅度局部重绘柔化过度蒙版查看临时查看附加网络前言为了更好的使用AI绘画,我们必须了解底层的Comfy......
  • 鸿蒙HarmonyOS实战-ArkUI事件(组合手势)
    ......
  • Mysql中的索引下推优化
    当索引下推开启后,如果where子句中的部分条件可以通过索引中的列来进行过滤,MySQL会把这部分条件也下推给存储引擎。这里的关键是下推的这部分条件用于过滤而非定位数据。直接看官方的例子:SELECT*FROMpeopleWHEREzipcode='95054'ANDlastnameLIKE'%etrunia%'ANDad......