<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 05/05/2017 09:00 PM, Daniel Goertzen
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAJCf5RxZ9iEaU6HyOVh6QFK4z_8ETrWNOEiUYS_1be1zhJ_j2Q@mail.gmail.com"
      type="cite">
      <pre wrap="">- When the resource stop() callback is invoked with is_direct_call==false,
is the provided environment considered a "process" environment? (ie, should
I pass it as the first parameter to enif_send() or leave null?)  Same
question for resource down() callback.
</pre>
    </blockquote>
    As a general rule you should pass the environment that you got
    <br>
    passed to your NIF or callback function. Pass NULL when you don't
    <br>
    have an environment which is only in a created thread.
    <br>
    <br>
    Maybe the documentation should be changed to talk about
    <br>
    "calling context" environments vs "dynamic term" environments
    <br>
    or something like that.
    <br>
    <br>
    The idea with the is_direct_call argument was to make lock handling
    <br>
    easier. If the resource has a mutex protecting its data, then
    enif_select
    <br>
    can be called without unlocking the mutex and use is_direct_call to
    determine
    <br>
    if the mutex is already locked or not.
    <br>
    <br>
    <blockquote
cite="mid:CAJCf5RxZ9iEaU6HyOVh6QFK4z_8ETrWNOEiUYS_1be1zhJ_j2Q@mail.gmail.com"
      type="cite">
      <pre wrap="">
- enif_select() appears to not add a reference to the associated resource.
What should happen if the resource gets garbage collected (dtor invoked)
while it has outstanding an enif_select()?

</pre>
      <br>
    </blockquote>
    enif_select <b class="moz-txt-star"><span class="moz-txt-tag">*</span>does<span
        class="moz-txt-tag">*</span></b> add a reference to the resource
    in the first call
    <br>
    and it releases the reference after the stop callback has returned.
    <br>
    <br>
    <a class="moz-txt-link-freetext"
href="https://github.com/erlang/otp/blob/OTP-20.0-rc1/erts/emulator/sys/common/erl_check_io.c#L1352">https://github.com/erlang/otp/blob/OTP-20.0-rc1/erts/emulator/sys/common/erl_check_io.c#L1352</a>
    <br>
    <br>
    <br>
    enif_monitor_process, however, does not add a reference to the
    resource.
    <br>
    <br>
    <br>
    Suggestions of how to improve the documentation is always welcome.
    <br>
    <br>
    /Sverker, Erlang/OTP
    <br>
  </body>
</html>