I have written a code in which there is a fork block and inside for block there is forever begin statement and inside this forever begin there is break statement. Can a break statement is used in a fork block?
As per SV LRM:- The continue and break statements cannot be used inside a fork-join block to control a loop outside the
fork-join block.
In reply to tech_savvy:
It would help to show some code, but I think in your case, the forever loop and break statements are both inside the fork-join. The break can only control looping within the same process.
In reply to dave_59:
@dave_59 can you please elaborate?
In reply to tech_savvy:
You can use the break statements inside forever which is a thread of fork join
example code:-
module mod;
int i = 8;
initial
begin
fork
forever
begin
$display(“inside forever i = %0d”,i);
if(i == 4)
break;
i–;
end
$display(“separate thread of fork join i = %0d”,i);
join
end
endmodule
Result:-
Compiler version J-2014.12-SP1-1; Runtime version J-2014.12-SP1-1; Jun 10 09:34 2019
inside forever i = 8
inside forever i = 7
inside forever i = 6
inside forever i = 5
inside forever i = 4
separate thread of fork join i = 4
V C S S i m u l a t i o n R e p o r t
In reply to rohit1501:
@rohit1501
Then what this statements means:- As per SV LRM:- The continue and break statements cannot be used inside a fork-join block to control a loop outside the
fork-join block. Please explain.
In reply to tech_savvy:
In reply to rohit1501:
@rohit1501
Then what this statements means:- As per SV LRM:- The continue and break statements cannot be used inside a fork-join block to control a loop outside the
fork-join block. Please explain.
break and continue statements can not be used inside a fork-join as a thread but can be used inside a loop which is a thread of fork-join ,like in my previous reply,
see below examples also
Example:- in this example break statement control a loop which is outside from fork-join, which is not allow as per SV LRM
module top;
initial begin
for (int i = 0; i < 10; i++)
fork
$display(i);
if(i == 5)
break;
join
end
endmodule
Result:-
“design.sv”, 10: token is ‘;’
break;
^
1 error
in this example break statement control a loop which is a thread or inside of fork-join, its possible
module top;
initial
begin
fork
for (int i = 0; i < 10; i++)
begin
$display(“i = %0d”,i);
if(i == 5)
break;
end
join
end
endmodule
Result:-
Compiler version J-2014.12-SP1-1; Runtime version J-2014.12-SP1-1; Jun 10 12:06 2019
i = 0
i = 1
i = 2
i = 3
i = 4
i = 5
V C S S i m u l a t i o n R e p o r t