shikharmakkar
Junior Member level 1

I am new to verilog and have a doubt concerning the race conditions in the following code which is taken from FPGA Prototyping by Veriloog Examples by Pong P. Chu. The code is:
This will infer races depending on which always block gets executed first. But always blocks should get executed in parallel. Correct me if I am wrong. I know there is blocking assignment but how does it affect the first statement of the block, which is the always statement?
The second code using the non-blocking assignment is:-
This will work fine according to the book but I couldn't understand why? Is it because the always blocks are executed in parallel in this case because of non-blocking assignment?
Code Verilog - [expand] 1 2 3 4 5 6 always @(posedge clk) a = b; always @(posedge clk) b = a;
This will infer races depending on which always block gets executed first. But always blocks should get executed in parallel. Correct me if I am wrong. I know there is blocking assignment but how does it affect the first statement of the block, which is the always statement?
The second code using the non-blocking assignment is:-
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 10 always @(posedge clk) begin //b(entry) = b a <= b; //a(exit) = b(entry) end //a = a(exit) always @(posedge clk) begin //a(entry) = a b <= a; //b(exit) = a(entry) end //b = b(exit)
This will work fine according to the book but I couldn't understand why? Is it because the always blocks are executed in parallel in this case because of non-blocking assignment?