[erlang-questions] enif_select() questions
Mon May 8 15:14:02 CEST 2017
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
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.
enif_monitor_process, however, does not add a reference to the resource.
Suggestions of how to improve the documentation is always welcome.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions