什么是竞争冒险?如何避免?
时间:2021-11-11 14:49:26
手机看文章
扫描二维码
随时随地手机看文章
[导读]竞争冒险这个含义其实广泛存在各个领域,本质上是指当两个或多个进程同时访问一个相同对象的场景。组合逻辑环moduleCMBLOP(o,a,b,c);outputo;inputa,b,c;rego;wirem=a|o;wiren=b|m;always@(corn)o=c|n;endm...
竞争冒险这个含义其实广泛存在各个领域,本质上是指当两个或多个进程同时访问一个相同对象的场景。
组合逻辑环
Verilog语句块有很多是并发的,不同的仿真器执行的顺序可能不一致 Write - Write Contention Race
组合逻辑环
module CMBLOP (o, a, b, c);
output o;
input a, b, c;
reg o;
wire m = a | o;
wire n = b | m;
always @(c or n)
o = c | n;
endmodule
在一般的数字设计中不用使用组合逻辑环,需要在其中进行插拍(异步设计除外)。 仿真竞争冒险:在两个或两个以上变量之间没有电路逻辑环,但有一个仿真反馈路径。module SIMLOP;
wire a, c;
reg b;
always @ (a or c) begin
b = a;
end
assign c = b;
endmodule
Verilog语句块有很多是并发的,不同的仿真器执行的顺序可能不一致 Write - Write Contention Race
module wr_wr_race (clk, a, b); //Write – Write Race
input clk,b;
output a;
wire d1, d2;
reg c1, c2, a;
always @(posedge clk) c1 = b;
always @(posedge clk) c2 = ~b;
assign d1 = c1;
assign d2 = c2;
always @(d1) a = d1;
always @(d2) a = d2;
endmodule
Write-Write竞争冒险可以通过将写入操作合并成单个进程来解决。 Read - Write Contention Racealways @(posedge clk) /* write process */
status_reg = new_val;
always @(posedge clk) /* read process */
status_output = status_reg;
上述读写竞争冒险可以通过non-blocking赋值解决。 避免竞争冒险的几个建议:1.使用non blocking赋值。2.一个寄存器只在单个语句块中赋值。3.assign赋值语句仅用来连接,不用来产生逻辑。