Tasks defined within a module, interface, program, or package default to being static, with all declared items
being statically allocated. These items shall be shared across all uses of the task executing concurrently.
Tasks can be defined to use automatic storage in the following two ways:
— Explicitly declared using the optional automatic keyword as part of the task declaration.
— Implicitly declared by defining the task within a module, interface, program, or package that is
defined as automatic.
Tasks defined within a class are always automatic (see 8.6).
All items declared inside automatic tasks are allocated dynamically for each invocation. All formal
arguments and local variables are stored on the stack.
Automatic task items cannot be accessed by hierarchical references. Automatic tasks can be invoked through
use of their hierarchical name.
Specific local variables can be declared as automatic within a static task or as static within an automatic
task.
大概意思就是class中task默认是automatic的
然后module、interface、program、package中是static的
automatic和static的区别
automatic : 每次启动task, task内部的变量都是分别放在不同地方来存储
例如
automatic task xixihaha();
int var1;
endtask
比如上面的task里面声明了var1,我们可能会重复调用xixihaha这个task,比如我们调用了3次,那么就有3个var1存在在3个不同的地方,3个task中的var1没有任何关联
使用场景就是就比如我们有多个进程调用这个task,然后我们又期望他们互不影响时候,(啰嗦一句,互不影响的意思就是我在进程2中调用task时不影响task1中的变量的值),此时就需要使用automatic
下面是例子和运行结果,供参考
module test();
//initial begin
generate
genvar i;
for(i=0; i<8; i++) begin
initial begin
haha(i);
end
end
endgenerate
//end
task haha(int i);
#100ns;
$display("time is %t, haha_%d",$time,i);
endtask
endmodule
结果如下
time is 100, haha_ 7
time is 100, haha_ 7
time is 100, haha_ 7
time is 100, haha_ 7
time is 100, haha_ 7
time is 100, haha_ 7
time is 100, haha_ 7
time is 100, haha_ 7
如果task haha变成task automatic haha,结果如下,
time is 100, haha_ 0
time is 100, haha_ 1
time is 100, haha_ 2
time is 100, haha_ 3
time is 100, haha_ 4
time is 100, haha_ 5
time is 100, haha_ 6
time is 100, haha_ 7
generate和automatic一般都是联合一起使用的。