转载:http://blog.sina.com.cn/s/blog_6c7b6f030101cpgt.html

begin-end and fork-join are used to combine a group of statements in a single block. General syntax with begin-end is as follows:

type_of_block @(sensitivity_list) 
begin: group_name 
 local_variable_declarations; 
 statements; 
end
           type_of_block may be initial or always. sensitivity_list is optional and possible only in always block. You are knowing about initial and always block in the previous chapter.

Sensitivity list is used to model sequential or combinational logic. To make it more clear, observe these examples:

module comb(a, b, c); 
input c; 
input b; 
output a; 
reg a; 
always @( c or b) 
begin 
         a = c & b; 
end 
endmodule
module seq(a, b, c); 
output a; 
input b; 
input c; 
reg a; 
always @( posedge c) 
begin 
       a <= b; 
end 
endmodule
          In the left hand side example, whenever c or b changes, a will become c & b. So it is combinational logic, represents and gate. Note that actual hardware register won't be implemented while synthesizing in the left-hand side example, even though it is declared as the type reg. Right hand side example will be synthesized as D-type Flip-flop since b will be assigned to a when ever c goes high. Difference between "=" and "<=" is explained in the next chapter. These codes can be represented in the form of circuits as shown below.

Output of module comb

Output of the module seq
            Inside an initial or always block, we can group statements using begin--end or fork--join. begin--endgroups two or more statements together sequentially, so that statements are evaluated in the order they are listed. Each timing control is relative to the previous statement. fork--join groups two or more statements together in parallel, so that all statements are evaluated concurrently. Each timing control is absolute to when the group started.

These are some examples to understand how begin--end and fork--join executes.

module forkjoin(clk, a, b); 
  input clk; 
  output a; 
  output b; 
  reg a, b; 
  initial 
  begin 
    a = 0; 
    b = 0; 
  end 
  always @(posedge clk) 
  fork 
  #2 a = 1; 
  #1 b = 1; 
  join 
endmodule
module forkjoin1(clk, a, b); 
input clk; 
output a; 
output b; 
reg a, b; 
initial 
begin 
 a = 0; 
 b = 0; 
end 
always @(posedge clk) 
fork 
#2 a = 1; 
#1 b = a; 
join 
endmodule

Output of forkjoin ^

Output of forkjoin1 ^

module beginend(clk, a, b);
    input clk;
    output a;
    output b;

reg a, b;

initial
    begin
       a = 0;
       b = 0;
    end

always @(posedge clk)
    begin
        #2 a = 1;
        #1 b = a;
    end
endmodule 
Output of beginend ^

From these examples, you can understand the execution.

We can nest begin--end and fork--join. That is, inside a begin--end we can have fork--join and inside fork--join we can have begin--end.  Consider these codes to find out how nested begin--end and fork--join works.

module nesting1(clk, a, b, c, d, e, f); 
 input clk; 
 output a, b, c, d, e, f; 
 reg a, b, c, d, e, f; 
 initial 
  begin 
   a = 0; 
   b = 0; 
   c = 0; 
   d = 0; 
   e = 0; 
   f = 0; 
 end 
 always @(posedge clk) 
  fork 
   #2 a = 1; 
   #2 b = 1; 
  begin 
   #2 c = 1; 
   #2 d = 1; 
   #2 e = 1; 
  end 
 #2 f = 1; 
join 
endmodule
and here is the output: You can notice that a, b, c and f became high 2 ns after the clock, d 2ns after c and e 2ns after d.

module nesting2(clk, a, b, c, d, e, f);
    input clk;
    output a, b, c, d, e, f;

reg a, b, c, d, e, f;

initial
    begin
       a = 0;
       b = 0;
       c = 0;
       d = 0;
       e = 0;
       f = 0;
    end

always @(posedge clk)
    begin
        #2 a = 1;
        #2 b = 1;
        fork
            #2 c = 1;
            #2 d = 1;
            #2 e = 1;
        join
        #2 f = 1;
    end
endmodule
Output wave of the above code is here. Notice that a, b and c became 1 with 2ns delay in-between, d and e became 1 together with c, after that f with 2 ns delay.

Program control will come out of the fork--join block when all the statements finishes executing. in the case of code bellow, control will come out of block after 30ns.

fork
   #20 c = 1;
   #30 d = 1;
   #10 e = 1;
join

关于Verilog中begin-end & fork-join的更多相关文章

  1. java并发编程(10)Fork/Join

    Fork/Join JAVA7中出现的Fork/Join,类似于分布式文件系统hadoop的mapreduce思想,就是将任务分割,再分割,直到分割到满足条件 为了便于理解:编程逻辑可以借用 递归的思 ...

  2. Fork/Join框架与Java8 Stream API 之并行流的速度比较

    Fork/Join 框架有特定的ExecutorService和线程池构成.ExecutorService可以运行任务,并且这个任务会被分解成较小的任务,它们从线程池中被fork(被不同的线程执行)出 ...

  3. 013-多线程-基础-Fork/Join框架、parallelStream讲解

    一.概述 Fork/Join框架是Java7提供了的一个用于并行执行任务的框架, 是一个把大任务分割成若干个小任务,最终汇总每个小任务结果后得到大任务结果的框架. 它同ThreadPoolExecut ...

  4. JAVA中的Fork/Join框架

    看了下Java Tutorials中的fork/join章节,整理下. 什么是fork/join框架 fork/join框架是ExecutorService接口的一个实现,可以帮助开发人员充分利用多核 ...

  5. java 中的fork join框架

    文章目录 ForkJoinPool ForkJoinWorkerThread ForkJoinTask 在ForkJoinPool中提交Task java 中的fork join框架 fork joi ...

  6. 关于verilog中语句可不可综合

    1)所有综合工具都支持的结构:always,assign,begin,end,case,wire,tri,aupply0,supply1,reg,integer,default,for,functio ...

  7. Fork/Join 型线程池与 Work-Stealing 算法

    JDK 1.7 时,标准类库添加了 ForkJoinPool,作为对 Fork/Join 型线程池的实现.Fork 在英文中有 分叉 的意思,而 Join 有 合并 的意思.ForkJoinPool ...

  8. 并发编程之Fork/Join

    并发与并行 并发:多个进程交替执行. 并行:多个进程同时进行,不存在线程的上下文切换. 并发与并行的目的都是使CPU的利用率达到最大.Fork/Join就是为了尽可能提高硬件的使用率而应运而生的. 计 ...

  9. fork/join并发编程

    Fork & Join 的具体含义 Fork 一词的原始含义是吃饭用的叉子,也有分叉的意思.在Linux 平台中,函数 fork()用来创建子进程,使得系统进程可以多一个执行分支.在 Java ...

  10. 多线程高并发编程(8) -- Fork/Join源码分析

    一.概念 Fork/Join就是将一个大任务分解(fork)成许多个独立的小任务,然后多线程并行去处理这些小任务,每个小任务处理完得到结果再进行合并(join)得到最终的结果. 流程:任务继承Recu ...

随机推荐

  1. xml和tomcat介绍

    一 xml介绍: xml:可扩展性的文件 功能: 1.作为框架的配置文件 2.方便在网络中传输数据 <a> <b></b> <c></c> ...

  2. tensorflow和keras混用

    在tensorflow中可以调用keras,有时候让模型的建立更加简单.如下这种是官方写法: import tensorflow as tf from keras import backend as ...

  3. for each...in

    for each...in 使用一个变量迭代一个对象的所有属性值,对于每一个属性值,有一个指定的语句块被执行. for each...in 是 ECMA-357 (E4X) 标准的一部分, 大部分非M ...

  4. 使用pca/lda降维

    PCA主成分分析 import numpy as np import pandas as pd import matplotlib.pyplot as plt # 用鸢尾花数据集 展示 降维的效果 f ...

  5. iOS 开发:绘制像素到屏幕

    转载:https://segmentfault.com/a/1190000000390012 译注:这篇文章虽然比较长,但是里面的内容还是很有价值的. 像素是如何绘制到屏幕上面的?把数据输出到屏幕的方 ...

  6. 微信小程序常见问题

    上拉加载与下拉刷新 https://blog.csdn.net/yelin042/article/details/71435628 微信小程序---报错:对应的服务器TLS为TLS 1.0,小程序要求 ...

  7. Win10系列:C#应用控件基础14

    ProgressBar控件 有时候用户需要执行比较复杂的任务,等待任务完成需要很长时间,在等待的过程中一般会使用进度条提示当前任务的执行进度,让用户更好的掌握任务的执行状态,例如在下载资源时会显示下载 ...

  8. 转载:escape,encodeURI,encodeURIComponent有什么区别?

    escape unescape encodeURI decodeURI encodeURIComponent decodeURIComponent 这六个方法功能有关联,如果不清楚每一个的作用,很容易 ...

  9. day41-python多进程多线程-多线程共享

    线程共享变量多线程和多进程不同之处在于多线程本身就是可以和父进程共享内存的,这也是为什么其中一个线程挂掉以后,为什么其他线程也会死掉的道理. import threading def worker() ...

  10. 大雄的elk实践

    目录 一.ElK环境搭建 1.1.elasticsearch 1..kibana 1..logstash二.elk实践 2.1 使用elk分析nginx日志 一.ElK环境搭建   1.1 elast ...