Static and automatic tasks

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一般都是联合一起使用的。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值