[erlang-questions] Static callback in NIF
Sergej Jurečko
sergej.jurecko@REDACTED
Thu Jun 30 11:04:41 CEST 2016
> On 29 Jun 2016, at 23:51, Igor Clark <igor.clark@REDACTED> wrote:
>
> Coming the other way works fine too, but relies on a C function callback which gets called when the hardware has a message for me. Right now I just have a static function in the NIF C code which I pass to the library. I create a static ErlNifEnv on NIF load() which I keep around and use in the callback to send messages to a specified erlang Pid, passed in via enif_get_local_pid() in another NIF function and also stored statically. This works a treat, but I'm feeling some pretty strong dread that it's very much the wrong way to do things, and asking for scheduler headaches/explosions.
If there is a better way of doing this I haven't found it and I've spent a lot of time in NIF's. An issue might be if you end up using the same environment variable across multiple threads.
Sergej
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160630/456a8d71/attachment.htm>
More information about the erlang-questions
mailing list