class a;
static int b;
static task update(int c = 0);
b = c;
$display("The value of b is = %0d", b);
endtask
endclass
module check();
a a1;
initial begin
a1 = new();
fork
begin
#3 a1.update(4);
end
begin
#3 a1.update(5);
end
join
end
endmodule
The output is:
The value of b is = 4
The value of b is = 5
Why the output is not 4,4 or 5,5 as I am using static task as well as static property?
You are correct, in that the last update which got executed will be the final value.
However, when you call update, you also immediately call $display, so the value is updated with the argument that is passed in and then displayed. There is nothing blocking between the assignment and $display to allow any task switching.
A better example would decouple the update and display:
class a;
static int b;
static function void print();
$display("At time %0d The value of b is = %0d", $time, b);
endfunction
static function void update(int c = 0);
b = c;
print();
endfunction
endclass
module check();
a a1;
initial begin
a1 = new();
fork
begin
#3 a1.update(4); // Update @time 3
#1 a1.print(); // Display @time 4
#3 a1.print(); // Display @time 7
end
begin
#5 a1.update(5); // Update @time 5
#1 a1.print(); // Display @time 6
end
join
end
endmodule
Note the lifetimes of your tasks are still automatic. The static qualifier on a class method means the method can be called without constructing the class and may only access static class members. See The life of a SystemVerilog variable