Task arguments behaviour in SV interface

I have a task defined in a virtual interface which should poll on some signals combination assertion . Those signals is arranged in arrays so the arguments intend to point to the desired signal in array to poll on :

 task wait_req_state(int a_idx,bit [3:0] a_state);
           @(posedge cb_clk.preq[a_idx] && (cb_clk.pstate[a_idx] == a_state));
  endtask 

Note : cb_clk is clocking block

I fork this task for idx=0 and idx=1 concurrently , but when I see that the condition is met for idx =0 , the other idx (1) is triggered too

fork 
my_ifc.wait_req_state(0,5);
my_ifc.wait_req_state(1,5);
join

This is probably some arguments issue in task for interfaces that I’m not aware off …

Just to note , that I have achieved the desired functionality by refactoring the task :

task wait_req_state(int a_idx,bit [3:0] a_state);
     case (a_idx)
          0 :  @(posedge cb_clk.preq[0] && (cb_clk.pstate[0] == a_state));
          1:  @(posedge cb_clk.preq[1] && (cb_clk.pstate[1] == a_state));   
     endcae 

  endtask

Will apreciate to get the root cause of the previous behaviour
Thanks

You should add automatic attribute to the task.

task automatic wait_req_state(int a_idx,bit [3:0] a_state);
   @(posedge cb_clk.preq[a_idx] && (cb_clk.pstate[a_idx] == a_state));
endtask 

initial
  fork 
    my_ifc.wait_req_state(0,5);
    my_ifc.wait_req_state(1,5);
  join

Otherwise, the same instance of task will be invoked.

1 Like

Also suggest keeping everything synchronized to the same clocking block event.

task automatic wait_req_state(int a_idx,bit [3:0] a_state);
   @(posedge cb_clk iff (cb_clk.preq[a_idx] && (cb_clk.pstate[a_idx] == a_state)));
endtask
1 Like

Thanks a lot Orimitsu and Dave , in SV classes the automatic declaration is not the mandatory as the tasks defined as automatic by default and this requirement is special for sv interfaces when tasks are by default not automatic , right ?
Summarizing this to get the bottom line explanation for this behaviour .

Class methods I have automatic lifetimes —you cannot declare them with static lifetimes. Everywhere else tasks and function declarations have static lifetimes as their default.