Quantcast

enif_select() questions

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

enif_select() questions

Daniel Goertzen-3

- 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.

- 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()?


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: enif_select() questions

Sverker Eriksson-4


On 05/05/2017 09:00 PM, Daniel Goertzen wrote:
- 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.
As a general rule you should pass the environment that you got
passed to your NIF or callback function. Pass NULL when you don't
have an environment which is only in a created thread.

Maybe the documentation should be changed to talk about
"calling context" environments vs "dynamic term" environments
or something like that.

The idea with the is_direct_call argument was to make lock handling
easier. If the resource has a mutex protecting its data, then enif_select
can be called without unlocking the mutex and use is_direct_call to determine
if the mutex is already locked or not.

- 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()?


enif_select *does* add a reference to the resource in the first call
and it releases the reference after the stop callback has returned.

https://github.com/erlang/otp/blob/OTP-20.0-rc1/erts/emulator/sys/common/erl_check_io.c#L1352


enif_monitor_process, however, does not add a reference to the resource.


Suggestions of how to improve the documentation is always welcome.

/Sverker, Erlang/OTP

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Loading...