问题描述
静态任务和自动任务有什么区别.
What is the difference between the static and automatic tasks.
program class_ref;
int index,value;
class holding_values;
int ass_array[*];
task assign_value (int value,int index);
ass_array[index] = value;
endtask
function void disp(int index);
$display("%t %M:ASSOSIATIVA VALUE%d ",$time,ass_array[index]);
endfunction
endclass
initial begin
holding_values obc;
index =5;
value =88;
obc = new();
map(obc,value);
obc.disp(index);
end
task map(ref holding_values obc,ref int value );
value +=5;
obc.assign_value(value,index);
obc =null;
endtask
endprogram
执行此代码会报错
引用参数在静态任务函数声明中是非法的
如果任务map"自动运行,则程序运行.
if task "map" is made to automatic the program runs.
为什么我们需要使任务自动化?静态任务和自动任务有什么区别?
Why do we need to make task automatic? What is the difference between static and automatic tasks?
推荐答案
对于静态任务,同一任务的多次调用将引用相同的局部变量.对于自动任务,局部变量对于任务的每次调用都是唯一的.
For a static task, multiple invocations of the same task will reference the same local variables. For an automatic task, the local variables will be unique to each invocation of the task.
这意味着对于以下任务:
This means that for the following task:
task some_task();
int foo = 5;
// ...
endtask
如果我们定义它static,那么所有调用都会看到 foo 的相同值(即 foo 将在它们之间共享).这意味着更改一个线程中的值将使所有其他线程也看到更改.
if we define it static, then all invocations will see the same value for foo (i.e. foo will be shared between them). This means that changing the value in one thread will make all others also see the change.
如果我们定义 some_task() 自动,那么每个调用都会有自己的 foo 本地副本,完全独立于其他的.在一个线程中更改 foo 不会对其他线程产生任何影响.
If we were to define some_task() automatic, then each invocation would have its own local copy of foo, totally independent of the others. Changing foo in one thread won't have any effect in others.
这篇关于自动任务和静态任务有什么区别,为什么我们不能通过引用静态任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!