[erlang-questions] ei_send multithreaded problem

lang er erlangist@REDACTED
Tue Feb 27 15:41:11 CET 2007


But in the erl_interface document, it said:


> If you are using Erl Interface functions in a threaded application based
> on POSIX threads or Solaris
> threads, then Erl Interface needs access to some of the synchronization
> facilities in your threads
> package, and you will need to specify additional compiler flags in order
> to indicate which of the
> packages you are using. Define REENTRANT and either STHREADS or PTHREADS.
> The default is to use
> POSIX threads if REENTRANT is specified.
> Note that both single threaded and default versions of the Erl interface
> and Ei libraries are provided.
> (The single threaded versions are named liberl interface st and libei st).
> Whether the default
> versions of the libraries have support for threads or not is determined by
> if the platform in question has
> support for POSIX or Solaris threads. To check this, have a look in the
> eidefs.mk file in the
> erl interface src directory.


I checked the eidefs.mk file, its content is:




# Have the ei and erl_interface libs been compiled for threads?
EI_THREADS=true

# Threads flags
THR_DEFS=-DWIN32_THREADS -DUSE_DECLSPEC_THREAD

# Threads libs
THR_LIBS=

# ----------------------------------------------------------------------

Doesn't it means I don't need use any synchronization facilities myself?

Thanks!

James


2007/2/26, Eduardo Figoli (INS) <eduardo@REDACTED>:
>
>  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/20070227/1a1672af/attachment.htm>


More information about the erlang-questions mailing list