Mailbox get/put inside a function is illegal in system verilog?

Hi

Wanted to confirm –
1.Can we use mailbox.get or mailbox.put inside function.

virtual function BitChk_status_e putDrvData (string name, int data);
if (bcDrvPoints.exists(name)) begin
bcDrvPoints[name].dp.mailbox.put(data);
end else
return FAIL;

    return PASS;

endfunction

The above gives me error that I cannot use delay.

If i replace the above function with task, it runs but gives me syntax error.
Can task be used to return enum data type (BitChk_status_e is enum type)

Please advise.
thanks
Ruchi

As per Verilog semantics, a function can not call a task. Mailbox put/get are blocking tasks hence the behavior you are seeing. Are your mailboxes unsized? Read more about mailbox’s non-blocking versions in the LRM if so. (try_put/try_get).

You should really check if you need plain mailbox than a tlm_port (variant of it maybe).

Cheers
Ajeetha, CVC