User guide

22-52
SystemVerilog Design Constructs
The context keyword enables, in this case, the C or C++
language function to call the user-defined task in the
SystemVerilog code. (This keyword also has other uses in the
DPI.)
The task keyword also enables the C or C++ language function
to call the user-defined task in the SystemVerilog code. We are
calling it a task even thought there are no tasks in C or C++.
You must include both keywords.
The SystemVerilog IEEE Std 1800-2005, Section 26.1.1 "Tasks and
functions", specifies the following:
“All functions used in DPI are assumed to complete their execution
instantly and consume 0 (zero) simulation time, just as normal
SystemVerilog functions.”
So imported C functions that call time-consuming user-defined tasks
must be declared to be tasks.
The SystemVerilog IEEE Std 1800-2005, Section 26.7 "Exported
tasks", specifies the following:
“It is never legal to call an exported task from within an imported
function.”
“It is legal for an imported task to call an exported task only if the
imported task is declared with the context property.”
Next comes the user-defined task:
task task_in_SV(inout int i);
#5 i = i/2;
endtask