[erlang-questions] Calling (equivalent of) erlang:send_after/3 from a NIF?

Igor Clark igor.clark@REDACTED
Mon Oct 29 21:06:00 CET 2018


I'd love to know a "proper" way of doing this too. I did something like it once by using signal(3) to set a callback to handle SIGALRM, scheduling the SIGALRM to get sent by the OS kernel with ualarm(3), and then sending the message to the appropriate pid in the callback. It had to keep static pointers to the ErlNifPid & message content (which I set with NIF "setter" functions) so that the callback could see them, and it used a fair bit of CPU when I used it with a repeating alarm at a short interval (like 500µs) to create a timed pulse, but I guess it wouldn't be a big problem if it was just an occasional attach/schedule/send/clear. But it did feel like I was doing something pretty wrong (ill-advised/evil) in the BEAM context.

> On 29 Oct 2018, at 16:48, Roger Lipscombe <roger@REDACTED> wrote:
> 
> I'd like to start a timer in my NIF. It should send a message to an
> Erlang process after a delay. There doesn't appear to be an
> enif_send_after.
> 
> Is there any way to do this?
> 
> (Obligatory "yes I know that NIFs are bad, mmkay...").
> 
> Regards,
> Roger.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list