In reply to dave_59:
Thank you, Dave.
Yes, I missed the clock inside the inner while loop. We have @(negedge clk) before the count++.
Most people will have join_any followed by disable fork. That means as soon as one of the processes you fork off terminates, then terminate all of the remaining processes.
In my case, I don't want the while(1) to terminate yet, so cannot use join_any and disable fork option for the original code.
You need a way to exit the while(1) loop.
Thanks for this, as I wasn't sure if the test would hang because of this while(1) loop. I understand I have to find a way to exit this loop for test to finish gracefully.
Can I add a big delay in the second begin-end statement of fork and then have join_any and disable fork to exit the while :
count = 0;
@ (posedge valid);
total_checks++; // no of times valid is asserted
while(valid == 1 || count <6) begin // while loop needs to loop for cycle for some checking after valid is asserted
end // while(1)
#x; //x is big enough to finish all the transactions in while(1) loop