Multithreading and Automatic variable

Below code will explains automatic vriable and multthreading.
For below code , for case-1 and case-2 output is different ,
module my_module;
int a=0;
initial
begin
for(int i=0;i<5;i++)
begin
fork
// Check differance here , between 2 statements
// ##case 1 (declaration and assignment). automatic int j= i;
// and
automatic int j;  // ##case 2 declare
j=i;                  //  then assign
begin
$display(“Chk auto %d”,j);
end
join_none
end
end
endmodule : my_module
For case-1 output is  0 1 2 3 4
For case-2 output is 5 5 5 5 5
for case-2 it creates 2 parallel threads while for case-1 it is just initial assignment of automatic variable.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s