静态任务和自动任务有什么区别。
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
如果执行此代码,它将给出错误
reference argument is illegal inside static task-function declaration
如果任务“map”自动运行,则程序运行。
为什么我们需要使任务自动化?静态任务和自动任务有什么区别?
最佳答案
对于 静态 任务,同一任务的多次调用将引用相同的局部变量。对于 自动 任务,局部变量对于任务的每次调用都是唯一的。
这意味着对于以下任务:
task some_task();
int foo = 5;
// ...
endtask
如果我们定义它 静态 ,那么所有调用都会看到相同的 foo 值(即 foo 将在它们之间共享)。这意味着更改一个线程中的值将使所有其他线程也看到更改。
如果我们将 some_task() 定义为自动的,那么每个调用都会有自己的 foo 本地副本,完全独立于其他调用。在一个线程中更改 foo 不会对其他线程产生任何影响。
关于system-verilog - 自动任务和静态任务有什么区别,为什么我们不能通过引用静态任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28021666/