[erlang-bugs] erl_interface and threads

Benjamin Winkler Benjamin.Winkler@REDACTED
Mon Apr 11 09:34:20 CEST 2011


Am 07.04.2011 20:15, schrieb Andrew Thompson:
> On Thu, Apr 07, 2011 at 01:08:37PM -0400, Michael Santos wrote:
>> On Thu, Apr 07, 2011 at 09:53:05AM +0200, Benjamin Winkler wrote:
>>> Hi!
>>>
>>> We are using Erlang and specifically the erl_interface for C (Visual
>>> Studio C++ 2008, Windows 7) to connect to our Erlang servers. We have
>>> noticed weird errors when creating (and freeing) terms in different
>>> threads. It seems to me that the memory allocation module is not
>>> thread-aware.
>> This isn't helpful with solving your problem with erl_interface but
>> have you looked at the newer ei interface? It lets you manage the memory
>> yourself (or allocates memory for you if you use the ei_x_* functions).
> I'm pretty sure that the whole point of ei is to be a thread-safe
> replacement for erl_interface.
Yes, that is what I ultimately did to solve the problem. Plus using a 
mutex to lock every single call to ETERM-allocation functions such as 
erl_mk_atom() and erl_free_term(). Tedious.

However, I did not find any notice of that behaviour in the 
erl_interface documentation. Also, ei provides a function 
ei_decode_term() which references the erl_interface library, and I'm 
pretty sure that this is not thread-safe as well as the whole problem 
seems to be the memory allocation for erlang terms. So all in all the 
conclusion would be: stay away from ETERM?

Benni




More information about the erlang-bugs mailing list