<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 29 Jun 2016, at 23:51, Igor Clark <<a href="mailto:igor.clark@gmail.com" class="">igor.clark@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">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.</span></div></blockquote></div><br class=""><div class="">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.</div><div class=""><br class=""></div><div class="">Sergej</div></body></html>