[erlang-questions] Accessing private data in a NIF C module

1 view
Skip to first unread message

zambal

unread,
Dec 14, 2009, 5:03:52 AM12/14/09
to erlang-q...@erlang.org
I could not found any information about if one needs to do any manual
locking when accessing data via enif_get_data(env) in an exported NIF
function. Does anybody know if this is needed?

thanks,
vincent

________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org

Sverker Eriksson

unread,
Dec 14, 2009, 6:19:05 AM12/14/09
to erlang-q...@erlang.org
zambal wrote:
> I could not found any information about if one needs to do any manual
> locking when accessing data via enif_get_data(env) in an exported NIF
> function. Does anybody know if this is needed?
>
Yes, you need to do your own locking on any data structures that you
introduce yourself and access either through enif_get_data() or static
variables. The callbacks load, reload, upgrade and unload are however
thread safe.

I will add more about this in the erl_nif documentation for next release.

/Sverker, Erlang/OTP Ericsson

zambal

unread,
Dec 14, 2009, 8:29:33 AM12/14/09
to erlang-q...@erlang.org
Thanks for the info. So using NIF is a bit dangerous indeed ;-) but I
guess it's mainly intended for small side-effect free functions.

-
vincent

Reply all
Reply to author
Forward
0 new messages