When should be program block dynamic or static ? members of static program block , members of automatic program blocks?

In reply to dave_59:

In reply to sriram.seshagiri:
Class methods and loop variable declarations are the only places where variable lifetimes are implicitly automatic by default. The variable i is covered by both these rules. The lifetime of eq_pa is not automatic, it’s dynamically allocated when constructing the class object. But there is still only one instance of it shared among all threads.
The call stack from the function hiarb_hifis_req() has nothing to do with this issue. You would see the same problem changing the $display inside the fork/join_none to
$display(“New EQ PAR : %0x\n”, eq_pa);
.
There are no race conditions here—everything is deterministic. The key point is that variables with automatic lifetimes get created upon each entry into a scope and persist until all nested scopes exit. Those nested scopes created by the fork/join_none don’t even start until after the for-loop terminates.

Thanks Dave. Yea everything is deterministic here in the sense the for loop executes fast enough and, it has reached its final value before the threads even start executing. I was thinking earlier that since both execute at time 0 there might be a race condition between the for loop and, forked off threads. But simulation showed me that the for loop reaches it’s end value before even the threads start executing which means the threads start executing the last because of the fork … join_none() construct.

Also regarding your comment of “Class methods and loop variable declarations are the only places where variable lifetimes are implicitly automatic by default. The variable i is covered by both these rules”.

In this example I still see variable i not being implicitly treated as an automatic variable in the for loop. And I see the variable i getting shared by all the threads resulting in unexpected results.
That was the reason I previously declared an automatic variable j and assigned it to i so that it gets initialized on each iteration of the for loop.

module top;
class dummy;

  int curr_pid;
  int eq_pa;
 
  task body();
 
 eq_pa = 'h100;
    for(int i=1; i<10; i++) begin

fork
//automatic int j = i;
automatic longint eq_pa_r = eq_pa;
  hiarb_hifis_req(eq_pa_r,i)
  //hiarb_hifis_req(eq_pa,i);
  $display("New EQ PAR : %0x\n", eq_pa_r);
join_none;
 
eq_pa = eq_pa + 'h40;
  $display("New EQ PA : %0x\n", eq_pa);
  $display("value of i : %0d\n", i);
end
  wait fork;
endtask
  
    function void hiarb_hifis_req(int pa, int i);
      $display("Processing thread %0d with EQ PA: %0x",i,pa);
  endfunction
  
  endclass

Output
New EQ PA : 140

value of i : 1

New EQ PA : 180

value of i : 2

New EQ PA : 1c0

value of i : 3

New EQ PA : 200

value of i : 4

New EQ PA : 240

value of i : 5

New EQ PA : 280

value of i : 6

New EQ PA : 2c0

value of i : 7

New EQ PA : 300

value of i : 8

New EQ PA : 340

value of i : 9

Processing thread 10 with EQ PA: 100
New EQ PAR : 100

Processing thread 10 with EQ PA: 140
New EQ PAR : 140

Processing thread 10 with EQ PA: 180
New EQ PAR : 180

Processing thread 10 with EQ PA: 1c0
New EQ PAR : 1c0

Processing thread 10 with EQ PA: 200
New EQ PAR : 200

Processing thread 10 with EQ PA: 240
New EQ PAR : 240

Processing thread 10 with EQ PA: 280
New EQ PAR : 280

Processing thread 10 with EQ PA: 2c0
New EQ PAR : 2c0

Processing thread 10 with EQ PA: 300
New EQ PAR : 300