<div>But in the erl_interface document, it said:</div>
<div> </div>
<div>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">If you are using Erl Interface functions in a threaded application based on POSIX threads or Solaris<br>threads, then Erl Interface needs access to some of the synchronization facilities in your threads
<br>package, and you will need to specify additional compiler flags in order to indicate which of the<br>packages you are using. Define REENTRANT and either STHREADS or PTHREADS. The default is to use<br>POSIX threads if REENTRANT is specified.
<br>Note that both single threaded and default versions of the Erl interface and Ei libraries are provided.<br>(The single threaded versions are named liberl interface st and libei st). Whether the default<br>versions of the libraries have support for threads or not is determined by if the platform in question has
<br>support for POSIX or Solaris threads. To check this, have a look in the <a href="http://eidefs.mk">eidefs.mk</a> file in the<br>erl interface src directory.</blockquote>
<div> </div>
<div>I checked the <a href="http://eidefs.mk">eidefs.mk</a> file, its content is:</div>
<div> </div>
<div> </div>
<div>
<p><br># Have the ei and erl_interface libs been compiled for threads?<br>EI_THREADS=true</p>
<p># Threads flags<br>THR_DEFS=-DWIN32_THREADS -DUSE_DECLSPEC_THREAD</p>
<p># Threads libs<br>THR_LIBS=</p>
<p># ----------------------------------------------------------------------<br></p>
<p>Doesn't it means I don't need use any synchronization facilities myself?</p>
<p>Thanks!</p>
<p>James</p></div><br> </div>
<div><span class="gmail_quote">2007/2/26, Eduardo Figoli (INS) <<a href="mailto:eduardo@inswitch.us">eduardo@inswitch.us</a>>:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div lang="EN-US" vlink="purple" link="blue">
<div>
<p><font face="Arial" color="navy" size="2"><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Have you tried using a critical section whenever calling ei_send?</span></font></p>
<p><font face="Arial" color="navy" size="2"><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"> </span></font></p>
<p><font face="Arial" color="navy" size="2"><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Regards, Eduardo</span></font></p>
<p><font face="Arial" color="navy" size="2"><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"> </span></font></p>
<div>
<div style="TEXT-ALIGN: center" align="center"><font face="Times New Roman" size="3"><span lang="ES" style="FONT-SIZE: 12pt">
<hr align="center" width="100%" size="2">
</span></font></div>
<p><b><font face="Tahoma" size="2"><span lang="ES" style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">De:</span></font></b><font face="Tahoma" size="2"><span lang="ES" style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">
 <a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:erlang-questions-bounces@erlang.org" target="_blank">erlang-questions-bounces@erlang.org</a> [mailto:<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:erlang-questions-bounces@erlang.org" target="_blank">
erlang-questions-bounces@erlang.org</a>] <b><span style="FONT-WEIGHT: bold">En nombre de </span></b>lang er<br><b><span style="FONT-WEIGHT: bold">Enviado el:</span></b> Lunes, 26 de Febrero de 2007 01:05 p.m.<br><b><span style="FONT-WEIGHT: bold">
Para:</span></b> <a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br><b><span style="FONT-WEIGHT: bold">Asunto:</span></b>
 [erlang-questions] ei_send multithreaded problem</span></font><span lang="ES"></span></p></div>
<div><span class="e" id="q_110febb5c8d7c31c_1">
<p><font face="Times New Roman" size="3"><span lang="ES-UY" style="FONT-SIZE: 12pt"> </span></font></p>
<div>
<p style="BACKGROUND: white"><font face="Arial" size="3"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Arial">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: 
</span></font></p>
<p style="BACKGROUND: white"><font face="Arial" size="3"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Arial"> </span></font></p>
<p style="BACKGROUND: white"><font face="Arial" size="3"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Arial">--------------------------------------------------------------------</span></font></p>
<p style="BACKGROUND: white"><font face="Arial" size="3"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Arial"> erlang_pid *pid = (erlang_pid *)pUser;<br> ei_x_buff xbuf;<br> ei_x_new_with_version(&xbuf);<br> ei_x_encode_tuple_header(&xbuf,2); 
<br> ei_x_encode_atom(&xbuf,"data");<br> ei_x_encode_binary(&xbuf, buffer, bufSize);<br> ei_send(acceptedFd, pid, xbuf.buff,xbuf.index);<br> ei_x_free(&xbuf);</span></font></p>
<p style="BACKGROUND: white"><font face="Arial" size="3"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Arial">----------------------------------------------------------------------</span></font></p>
<p style="BACKGROUND: white"><font face="Arial" size="3"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Arial"> </span></font></p>
<p style="BACKGROUND: white"><font face="Arial" size="3"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Arial"> </span></font></p>
<p style="BACKGROUND: white"><font face="Arial" size="3"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Arial">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.) 
</span></font></p>
<p style="BACKGROUND: white"><font face="Arial" size="3"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Arial"> </span></font></p>
<p style="BACKGROUND: white"><font face="Arial" size="3"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Arial"> </span></font></p>
<p style="BACKGROUND: white"><font face="Arial" size="3"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Arial">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. 
</span></font></p>
<p style="BACKGROUND: white"><font face="Arial" size="3"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Arial"> </span></font></p>
<p style="BACKGROUND: white"><font face="Arial" size="3"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Arial">Do I miss anything to use ei_send in multithreaded environment?</span></font></p>
<p style="BACKGROUND: white"><font face="Arial" size="3"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Arial"> </span></font></p>
<p style="BACKGROUND: white"><font face="Arial" size="3"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Arial">compiler: ms visual studio 2005</span></font></p>
<p style="BACKGROUND: white"><font face="Arial" size="3"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Arial">debug mode use  ei_mdd.lib </span></font></p>
<p style="BACKGROUND: white"><font face="Arial" size="3"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Arial"> </span></font></p>
<p style="BACKGROUND: white"><font face="Arial" size="3"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Arial"> </span></font></p>
<p style="BACKGROUND: white"><font face="Arial" size="3"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Arial"> </span></font></p>
<p style="BACKGROUND: white"><font face="Arial" size="3"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Arial">Thanks,</span></font></p>
<p style="BACKGROUND: white"><font face="Arial" size="3"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Arial">James</span></font></p>
<p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt"> </span></font></p></div></span></div></div></div></blockquote></div><br>