<div dir="ltr">I see another scenario here: What happens in the context of enif_send() in a scoped thread? That is, in my NIF function I spin up a thread that does an enif_send() and exits before my NIF function returns. The process environment is in fact in scope for the enif_send, but I'm also in a created thread. Should I plug in the process environment or null?</div><br><div class="gmail_quote"><div dir="ltr">On Sat, Jan 14, 2017 at 1:04 AM Jason Orendorff <<a href="mailto:jason.orendorff@gmail.com">jason.orendorff@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">On Fri, Jan 13, 2017 at 10:09 AM, Sverker Eriksson <span dir="ltr" class="gmail_msg"><<a href="mailto:sverker.eriksson@ericsson.com" class="gmail_msg" target="_blank">sverker.eriksson@ericsson.com</a>></span> wrote:<br class="gmail_msg"></div><div dir="ltr" class="gmail_msg"><div class="gmail_extra gmail_msg"><div class="gmail_quote gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="gmail_msg">On 01/12/2017 08:21 PM, Jason Orendorff wrote:</span><span class="gmail_msg"><br class="gmail_msg">
<blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
4. We suspect it's actually totally safe to pass a process-independent<br class="gmail_msg">
environment as the first parameter, regardless of whether there's a<br class="gmail_msg">
"calling process" or we're "calling from a created thread". Is it?<br class="gmail_msg">
If so, would you accept a patch to document that that's OK?<br class="gmail_msg">
</blockquote></span>
I'm not super excited about such a guarantee, at least not right now.<br class="gmail_msg"></blockquote></div></div></div><div dir="ltr" class="gmail_msg"><div class="gmail_extra gmail_msg"><div class="gmail_quote gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"></blockquote><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Thank you for the quick, thoughtful response. I appreciate your time.<br class="gmail_msg"></div><br class="gmail_msg"></div><div class="gmail_quote gmail_msg">Is there a way to enforce this rule for our users that we've missed? When<br class="gmail_msg">our `send` method is called, I think we have to figure out if there's a current<br class="gmail_msg">calling process, and if so, its environment. I don't see a way to do it without<br class="gmail_msg">storing that information in TLS ahead of time -- at a cost to every NIF call.<br class="gmail_msg"></div><br class="gmail_msg"></div><div class="gmail_extra gmail_msg">We could make code that runs on created threads statically different from<br class="gmail_msg">code that runs in the Erlang scheduler's threads, e.g. by making<br class="gmail_msg">`NifCallEnv`, `AllocatedEnvInNifThread`, and `AllocatedEnvInCreatedThread`<br class="gmail_msg"></div><div class="gmail_extra gmail_msg">three different types, of which only 2 have `.send()` methods. But this<br class="gmail_msg"></div><div class="gmail_extra gmail_msg">seems horrible.<br class="gmail_msg"></div><div class="gmail_extra gmail_msg"><br class="gmail_msg"></div><div class="gmail_extra gmail_msg">We have considered several possible approaches, all about as bad as that.<br class="gmail_msg"></div><div class="gmail_extra gmail_msg"><br class="gmail_msg"></div><div class="gmail_extra gmail_msg">Thanks,<br class="gmail_msg"></div><div class="gmail_extra gmail_msg"><div class="gmail_quote gmail_msg">-j<br class="gmail_msg"><br class="gmail_msg"></div></div></div>
_______________________________________________<br class="gmail_msg">
erlang-questions mailing list<br class="gmail_msg">
<a href="mailto:erlang-questions@erlang.org" class="gmail_msg" target="_blank">erlang-questions@erlang.org</a><br class="gmail_msg">
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" class="gmail_msg" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br class="gmail_msg">
</blockquote></div>