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

Roger Lipscombe roger@REDACTED
Mon Oct 29 22:26:58 CET 2018

On 29 October 2018 at 20:06, Igor Clark <igor.clark@REDACTED> wrote:
> 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.

Yeah; I found timer_create and timer_start, which Linux implements,
and apparently supports 1ms granularity, but they use signals, and it
makes me uneasy to do signal-stuff inside the BEAM.

More information about the erlang-questions mailing list