system verilog example fork join / fork join_none/ fork join_any example codes
*module test;
int d,result;
int a=2,b=3;
function automatic mult(input int a,input int b,output int c);
c=(a*b)+2;
$display("inside function");
$display("$time =%d,a=%d,b=%d,c=%d",$time,a,b,c);
endfunction
initial
fork
begin
#1;
mult(2,3,d);
$display("//////");
$display("$time =%d,a=%d,b=%d,d=%d",$time,a,b,d);
end
begin
#2;
mult(2,4,d);
$display("//////");
$display("$time =%d,a=%d,b=%d,d=%d",$time,a,b,d);
end
join
endmodule*/
/*module test;
int d,result;
int a=2,b=3;
function automatic mult(ref int a,ref int b,output int c);
c=(a*b)+2;
a++;
$display("inside function");
$display("$time =%d,a=%d,b=%d,c=%d",$time,a,b,c);
endfunction
initial
fork
begin
#1;
//mult(2,3,d);
mult(a,b,d);
$display("//////");
$display("$time =%d,a=%d,b=%d,d=%d",$time,a,b,d);
end
begin
#2;
//mult(2,4,d);
mult(a,b,d);
$display("//////");
$display("$time =%d,a=%d,b=%d,d=%d",$time,a,b,d);
end
join
endmodule*/
/*module test;
int d,result;
int a=2,b=3;
function mult(input int a,input int b,output int c);
c=(a*b)+2;
a++;
$display("inside function");
$display("$time =%d,a=%d,b=%d,c=%d",$time,a,b,c);
endfunction
initial
fork
begin
#1;
mult(a,b,d);
$display("//////");
$display("$time =%d,a=%d,b=%d,d=%d",$time,a,b,d);
end
begin
#2;
mult(a,b,d);
$display("//////");
$display("$time =%d,a=%d,b=%d,d=%d",$time,a,b,d);
end
join
endmodule*/
/*
module test;
int d,result;
int a=2,b=3;
task automatic mult(input int a,input int b,output int c);
c=(a*b)+2;
a++;
$display("inside function");
$display("$time =%d,a=%d,b=%d,c=%d",$time,a,b,c);
endtask
initial
fork
begin
#1;
mult(a,b,d);
$display("//////");
$display("$time =%d,a=%d,b=%d,d=%d",$time,a,b,d);
end
begin
#2;
mult(a,b,d);
$display("//////");
$display("$time =%d,a=%d,b=%d,d=%d",$time,a,b,d);
end
join
endmodule
*/
/*
module test;
int d,result;
int a=2,b=3;
task automatic mult(input int a,input int b,output int c);
c=(a*b)+2;
a++;
$display("inside function");
$display("$time =%d,a=%d,b=%d,c=%d",$time,a,b,c);
endtask
initial
fork
begin
#1;
mult(2,3,d);
$display("//////");
$display("$time =%d,a=%d,b=%d,d=%d",$time,a,b,d);
end
begin
#2;
mult(2,4,d);
$display("//////");
$display("$time =%d,a=%d,b=%d,d=%d",$time,a,b,d);
end
join
endmodule
*/
/*class pass_by_ref;
int refr=2;
int val=2;
function automatic int check_refer(ref int r);
$display("pass by ref");
$display("initial value of refr=%d",r);
r++;
$display("after incrementing %d",r);
endfunction
function int check_value(int v);
$display("pass by value");
$display("initial value of value=%d",v);
v++;
$display("after incrementing %d",v);
endfunction
endclass
pass_by_ref h1;
module test;
initial
begin
h1=new();
h1.check_refer(h1.refr);
h1.check_value(h1.val);
$display("inside memory");
$display("%d",h1.refr);
$display("%d",h1.val);
end
endmodule*/
module test;
task dummy_task(input int x,string str);
fork
begin
#x;
end
begin
#10;
end
join_any
disable fork;
$display("%s:%t",str,$time);
endtask
initial
fork
begin
#2;
dummy_task(5,"call_1");
end
begin
#1;
dummy_task(15,"call_2");
end
join
endmodule
`
/*
module test;
int d,result;
int a=2,b=3;
function automatic mult(input int a,input int b,output int c);
c=(a*b)+2;
$display("inside function");
$display("$time =%d,a=%d,b=%d,c=%d",$time,a,b,c);
endfunction
initial
fork
begin
#1;
mult(2,3,d);
$display("//////");
$display("$time =%d,a=%d,b=%d,d=%d",$time,a,b,d);
end
begin
#2;
mult(2,4,d);
$display("//////");
$display("$time =%d,a=%d,b=%d,d=%d",$time,a,b,d);
end
join
endmodule
*/
/*
module test;
int d,result;
int a=2,b=3;
function automatic mult(ref int a,ref int b,output int c);
c=(a*b)+2;
a++;
$display("inside function");
$display("$time =%d,a=%d,b=%d,c=%d",$time,a,b,c);
endfunction
initial
fork
begin
#1;
//mult(2,3,d);
mult(a,b,d);
$display("//////");
$display("$time =%d,a=%d,b=%d,d=%d",$time,a,b,d);
end
begin
#2;
//mult(2,4,d);
mult(a,b,d);
$display("//////");
$display("$time =%d,a=%d,b=%d,d=%d",$time,a,b,d);
end
join
endmodule
*/
/*
module test;
int d,result;
int a=2,b=3;
function mult(input int a,input int b,output int c);
c=(a*b)+2;
a++;
$display("inside function");
$display("$time =%d,a=%d,b=%d,c=%d",$time,a,b,c);
endfunction
initial
fork
begin
#1;
mult(a,b,d);
$display("//////");
$display("$time =%d,a=%d,b=%d,d=%d",$time,a,b,d);
end
begin
#2;
mult(a,b,d);
$display("//////");
$display("$time =%d,a=%d,b=%d,d=%d",$time,a,b,d);
end
join
endmodule
*/
/*module test;
int d,result;
int a=2,b=3;
task automatic mult(input int a,input int b,output int c);
c=(a*b)+2;
a++;
$display("inside function");
$display("$time =%d,a=%d,b=%d,c=%d",$time,a,b,c);
endtask
initial
fork
begin
#1;
mult(a,b,d);
$display("//////");
$display("$time =%d,a=%d,b=%d,d=%d",$time,a,b,d);
end
begin
#2;
mult(a,b,d);
$display("//////");
$display("$time =%d,a=%d,b=%d,d=%d",$time,a,b,d);
end
join
endmodule*/
/*module test;
int ma=20;
function void pass_by_value(int fa);
fa=fa*2;
$display("inside the function pass_by_value fa=%d", fa);
endfunction : pass_by_value
function automatic void pass_by_ref(ref int fa);
fa=fa*2;
$display(" inside the function pass_by_ref fa=%d",fa);
endfunction:pass_by_ref
initial
begin
pass_by_value(ma);
$display("after calling the function pass_by_value ma=%d", ma);
pass_by_ref(ma);
$display("after calling the function pass_by_ref ma=%d", ma);
end
endmodule:test*/
Comments
Post a Comment