Automatic variables in fork

In reply to dave_59:

Hi Dave,

I have run this code (test4)on the VCS simulator and but it prints 2, 2, 2.
Now based on the explanation you have given earlier, the activation scope for k (in program test4) is the begin…end block of for loop. So k will get values 0,1,2 and these values will be used by $write(k) and it should print 0,1,2. This is unlike cases 2 and 3 above where k is activated in begin end block inside fork, which gets scheduled after #0 delay and by that time j would have reached 3. So it uses j ==3 for all 3 processes and prints 3,3,3 (let me know if this understanding is correct).
I am not clear why VCS is giving different result. I have tried replacing program with module statement, but it makes no difference.
Also you have said “The only difference would be visibility of the variable k after the fork statement if there were other statements.” in your comment. Can you please elaborate on this.

thanks
-sunil