fork join_any 中的语句与其后面的语句同时执行时是否保证执行顺序

问题描述 投票:0回答:1
module test();
reg a,b,c,d;
initial begin
    fork
        #5  $display("Fork Time is %0t",$time);
        #10 $display("Fork Time is %0t",$time);
        #15 $display("Fork Time is %0t",$time);
    join_any
    #5 $display("Time is %0t",$time);
    #5 $display("Time is %0t",$time);
end
endmodule

标准保证顺序块中的语句按顺序执行,但是如果顺序块中的

fork
join_any
join_none
会导致并行块后面的语句与并行块中的语句同时执行block,它们的执行顺序有保障吗?我尝试了很多模拟器,结果是:

# Fork Time is 5
# Fork Time is 10
# Time is 10
# Fork Time is 15
# Time is 15

我猜测并行块中的语句会先于并行块之后同时执行的语句执行,但我找不到任何证据。

verilog system-verilog hdl
1个回答
0
投票

您显示的输出是预期的。

我在您的代码中添加了一些注释以唯一标识每个显示语句:

initial begin
    fork
        #5  $display("Fork Time is %0t",$time); // d1: Start execution at t= 0, display at t= 5
        #10 $display("Fork Time is %0t",$time); // d2: Start execution at t= 0, display at t=10
        #15 $display("Fork Time is %0t",$time); // d3: Start execution at t= 0, display at t=15
    join_any
    #5 $display("Time is %0t",$time);           // d4: Start execution at t= 5, display at t=10
    #5 $display("Time is %0t",$time);           // d5: Start execution at t=10, display at t=15
end

fork
块在时间 0 开始执行。
join_any
行之后的第一个显示语句只有在
fork/join_any
允许之后才会开始执行。由于 d1 在
fork
块内 5 个时间单位的延迟最短,因此 d1 将首先完成。所以,在时间 5,d1 执行完毕,然后 d4 语句开始执行。

© www.soinside.com 2019 - 2024. All rights reserved.