[erlang-questions] When to release resources in NIF?

Soup zachary.hueras@REDACTED
Mon Mar 24 15:17:10 CET 2014


Theoretically, you should be able to use the "upgrade" or "reload"
callbacks in your NIF instead of the unload callback. It may be necessary
to perform the upgrade as an app/relup to use that feature, though. Perhaps
someone a bit more versed on NIF modules can shed some light.

At the very least you need to specify one of those two callback functions.

~Soup


On Fri, Mar 21, 2014 at 1:15 PM, Attila Rajmund Nohl <
attila.r.nohl@REDACTED> wrote:

> Hello!
>
> I have a NIF module that uses a locks to protect a common resource.
> The locks are created using enif_rwlock_create in the load function
> and destroyed in the unload function. When I first load the Erlang
> module, the locks are initialized and everything is OK. When I compile
> the module in the same VM the first time, everything is still OK. When
> I compile it the second time, the old version of the module is
> unloaded, so unload is called. At this point I'm in trouble, because
> the unload function destroys the lock.
>
> I'm not quite sure how to correctly handle this situation. Somehow I
> should keep (or destroy/create) the locks in the upgrade step, but
> after the second compilation the locks are already deleted by unload.
> I could add a flag to the private data stating that the locks were
> already destroyed or not, but it feels hackish. What is the correct
> way?
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140324/f7c1b8cf/attachment.htm>


More information about the erlang-questions mailing list