[erlang-questions] enif_release_resource and enif_make_resource

Max Lapshin max.lapshin@REDACTED
Thu Jul 4 16:11:24 CEST 2019


I have following code in nif:

State *s = enif_alloc_resource(..)
enif_self(env, &s->owner);
ERL_NIF_TERM term = enif_make_resource(env, s);
enif_release_resource(s);
return term;


Then later another thread (not written by me) is calling my callback
function:


void mycallback(void *obj)
{
  State *s = obj;
  ErlNifEnv *msg_env = enif_alloc_env();
  ERL_NIF_TERM term = enif_make_resource(msg_env, s);
  enif_send(NULL, &s->owner, msg_env, term);
  enif_free_env(msg_env);
}


Is this code correct?

Should I put release_resource for each make_resource or only for
release_resource?

Is this calling of enif_send correct?

I'm afraid that I miss these answers in documentation or cannot find them.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190704/b5ea5bc1/attachment.htm>


More information about the erlang-questions mailing list