[erlang-questions] ei_send multithreaded problem

Eduardo Figoli (INS) eduardo@REDACTED
Mon Feb 26 16:46:32 CET 2007


Have you tried using a critical section whenever calling ei_send?

 

Regards, Eduardo

 

  _____  

De: erlang-questions-bounces@REDACTED
[mailto:erlang-questions-bounces@REDACTED] En nombre de lang er
Enviado el: Lunes, 26 de Febrero de 2007 01:05 p.m.
Para: erlang-questions@REDACTED
Asunto: [erlang-questions] ei_send multithreaded problem

 

I'm writing a c node using ei layer. This program is running under Window
2003 enterprise edition sp1, and otp_win32_R11B-3. The following is a
fragment of my code: 

 

--------------------------------------------------------------------

 erlang_pid *pid = (erlang_pid *)pUser;
 ei_x_buff xbuf;
 ei_x_new_with_version(&xbuf);
 ei_x_encode_tuple_header(&xbuf,2); 
 ei_x_encode_atom(&xbuf,"data");
 ei_x_encode_binary(&xbuf, buffer, bufSize);
 ei_send(acceptedFd, pid, xbuf.buff,xbuf.index);
 ei_x_free(&xbuf);

----------------------------------------------------------------------

 

 

It is called inside a C callback function and may be called by many
concurrent threads. pUser include a erlang_pid (correspond to a process in
Erlang side).When some data come from network, a third party library will
invoke this callback function, so ei_send pass these data to a corresponding
Erlang process.(This process is an Erlang equivalent to a 3rd library
thread. So if I start one process in Erlang side, the 3rd library will use
one thread. If I start more than one process in Erlang , the 3rd library
will use same number of threads.) 

 

 

Then, If I start one process in Erlang side, everything is OK. But If I
start more than one process, the C node program will crash after some random
time. If I comment  out ei_send line in above code fragment, everything is
OK again. 

 

Do I miss anything to use ei_send in multithreaded environment?

 

compiler: ms visual studio 2005

debug mode use  ei_mdd.lib 

 

 

 

Thanks,

James

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20070226/8d72c50d/attachment.htm>


More information about the erlang-questions mailing list