Hi All,
In my simulation I want to prioritize between different initial begin.
Let us say for example I have following initial begins.
// first initial begin
initial begin
$display ("This is first block ");
end
initial begin
$display(“This is second block”);
end
**initial begin
$display(“This is third block”);
end
**
All displays are displayed at 0 ns, but we can not determine which will be executed first.
I want to make sure the third block gets executed first and than other block’s execution starts.
I do not care about the order of the other initial begins.
In my system there are lot of such initial begin and distributed in different files and modules. So I have to find solution in last three line of the code. Can anybody help me here?
Thanks,
Sandip
In reply to bhadanisandip:
There are many possible solutions, but without knowing the motivation behind your request, it is difficult to give you the most efficient way.
Most of the time, this introduces a race in variable initialization. Sometimes you can move the initialization to the variable declaration, which executes before the initial block.
int A = some_function();
initial $display("A is %d", A);
If you start having more levels of dependancies, then you need to move to a “initialize on first use” coding pattern. This is where you never refer to a variable directly, but instead use a function to check the value and initialize it before returning its value.
class A;
endclass
A handle;
function A get_handle();
if (A==null)
A = new();
return A;
endfunction
In reply to bhadanisandip:
using event + wait(event.trigger) to control sequence and avoid race condition
event first_done;
event second_done;
initial begin
$display("this is the 1st block");
->first_done;
end
initial begin
wait(first_done.triggered);
$display("this is the 2nd block");
->second_done;
end
initial begin
wait(second_done.triggered);
$display("this is the 3rd block");
end