I have a very simple piece of code that is boggling my mind.
->ev1; //Trigger the event of interest
fork : main_fork
begin : T1
$display("T1 is RUNNING");
fork
begin
$display("T1.B3 is RUNNING");
$display("T1.B3 END");
end
begin
$display("T1.B0 is RUNNING");
$display("T1.B0 END");
end
join
$display("T1 END");
end : T1
begin :T2
$display("T2 is RUNNING");
@ev1;
$display("T2 END");
end : T2
join_any : main_fork
disable main_fork;
So, the idea is when ev1
happens, I want T2 to end and thus effectively killing everything in T1. If ev1
never happens, then I want both the threads T1.B3 followed by T1.B0 to execute and and proceed to the code after disable main_fork.
Now, here is the funny/confusing part. When I grep for the above statements, I can see a set of RUNNING prints at timestamp:X ... but I never see any of the END prints and then again at timestamp:X+100, I once again see all the RUNNING prints.
I can see event ev1
has happened AFTER we start running T2 for the first time, I expected T2 to be killed at that point, END print of T2 to come. But, it looks like T2 never ends when ev1
happens and magically, all the threads start once again.
How can threads re-start when they do not end? Why wasn't the event recognized even when we started waiting for them before the event actually occurred?