In reply to saritr:
*In reply to dave_59:*What for the begin and end inside the fork?
I was just trying to keep the two examples as similar as possible. A begin/end around a single statement does not do anything meaningful. The fork/join_any still creates two processes.
Look at this simpler example
module top;
int A,B,C;
initial forever fork : outer
#1 A = A + 1;
forever begin : inner
fork
#2 B = B + 1;
#4 C = C + 1;
join_any
disable fork;
end : inner
join : outer
endmodule
The outer forever loop only executes once; it behaves the same as if there was no outer forever keyword.
The outer fork creates two processes, one for the
#1 A = A + 1; statement, and one for the inner forever loop. The inner forever loop executes a inner fork/join_any that creates two more processes; the assignments to B and C.
The process that makes the assignment to A completes at time 1, then the process that makes the assignment to B completes at time 2. The join_any happens at time 2, and the process that would make the assignment to C gets disabled. Now we have gotten to the end of the inner forever loop, and we repeat the inner fork. So the assignment to B happens at times 2,4,6,8, etc. The assignment to C never occurs because the statement gets disabled before ever having a chance to execute.
The outer fork never joins because the second process it spawns never finishes. It is an infinite forever loop. Since the outer fork never joins, the outer forever loop never has a chance to repeat.