静态任务和自动任务有什么区别?
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”设置为自动,程序就会运行。
为什么我们需要使任务自动化?静态任务和自动任务有什么区别?
For a static任务中,同一任务的多次调用将引用相同的局部变量。为自动的任务时,局部变量对于任务的每次调用都是唯一的。
这意味着对于以下任务:
task some_task();
int foo = 5;
// ...
endtask
如果我们定义它static,那么所有调用都会看到相同的值foo (i.e. foo将在他们之间共享)。这意味着更改一个线程中的值将使所有其他线程也看到更改。
如果我们要定义一些_任务()自动,那么每次调用都会有自己的本地副本foo,完全独立于其他人。改变foo在一个线程中不会对其他线程产生任何影响。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)