In reply to dave_59:
Thanks Dave for your suggestion.
I have one more doubt. In the below attached snippet what is the difference if i declare automatic int ch=i inside for_begin block or inside fork_join_none block(as i have commented in the code)
If i use automatic int ch=i inside fork_join_none block ,that statement will also be treated as separate thread and there will be two different threads one is automatic int ch=i and one more is begin_end block inside fork_join_none. And what if begin_end block inside fork_join_none tries to get ch value before it is updated.
NOTE :- I have corrected my typo as you suggested in above reply.
module test;
class member;
task main_task(bit[7:0] a,b,c,d);
fork
sub_task(a,b,"FIRST THREAD");
sub_task(c,d,"SECOND THREAD");
join
endtask
task automatic sub_task(bit[7:0] p,q,string label);
bit[7:0] m,n;
for(int i=0;i<3;i++)
begin //for begin
automatic int ch=i;
fork
//automatic int ch=i;
begin //fork begin
m=p*ch;
n=q*ch;
$display("Tag=%s,m=%0d,n=%0d,i=%0d",label,m,n,i);
end //fork end
join_none
end //for end
endtask
endclass
member m1;
initial begin
m1=new();
for(int i=1;i<5;i++) begin
m1.main_task(i,i+1,i+2,i+3); end
end
endmodule