[erlang-questions] When to release resources in NIF?
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.
On Fri, Mar 21, 2014 at 1:15 PM, Attila Rajmund Nohl <
> 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
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions