In reply to naveensv:
I’m not able to call task from function using fork/join_none. function_calling_task - EDA Playground
Could someone help to explain why I don’t see display statement. I will appreciate the help.
module test;
task xyz; #100;
$display(“I’m in xyz\n”);
endtask
function void b;
fork
xyz;
join_none
endfunction
// put these lines
initial begin
b;
end
endmodule
Hi Abdul,
I used it in a Scoreboard. Inside the virtual write function. I have put a task under fork - join_none, which will go and check and do data comparison of all bursts for each request.
Looks like this link is not valid anymore. Can you please point to an active link?
If not please let me know if there is a way we can call a task from within a function with an example.
In reply to dave_59:
Hi,
Below code is working, but I was expecting a task (time consuming) can’t be called inside a function. Does that matter how function is getting called?
module tb;
initial
repeat(2)
begin
fork
functio_n;
join
end
function functio_n;
$display($time, "\t function");
tas_k;
endfunction
task tas_k;
$display($time, "\t task");
endtask
endmodule
This task isn’t time consuming. so it’s expected to work fine.
No, it doesn’t matter how function is getting called.
Functions have restrictions that make certain they return without suspending the process that enables them. The following rules shall govern their usage, with exceptions noted in 13.4.4:
A function shall not contain any time-controlled statements. That is, any statements containing #, ##, @, fork-join, fork-join_any, wait, wait_order, or expect.
A function shall not enable tasks regardless of whether those tasks contain time-controlling
statements.
The noted exceptions are statements inside a fork/join_none.
Some tools only apply restriction a) because in Verilog, there was no way to write a function without it being part of an expression, so there a people still writing tasks when they should be using function void.
But you are setting yourself up for a maintenance nightmare if you have several levels of nested functions and tasks calls, and someone introducers a blocking construct inside a deeply nested task.
So use a function when you want a guarantee that the procedure does not block.