<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I once had the same problem, but with the .NET version of the ESL library. <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I was told on this mailing list to not have multiple Threads access the same ESLconnection object. <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>In .NET I’d get a AccessViolationException. <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Having two connections to FS ESL would probably be better; one for receiving, the other for sending commands. <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>The connection for receiving events could then also distribute the events to all other components in your program which require these events. <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>This way only one object is concerned with the retrieval of ESL events, while you could have multiple others processing them without ever touching the eslconnection. <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Hope this helps.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] <b>On Behalf Of </b>Shlomi Agiv<br><b>Sent:</b> Tuesday, August 5, 2014 10:14 AM<br><b>To:</b> FreeSWITCH Users Help<br><b>Subject:</b> [Freeswitch-users] esl_recv_event() from two threads on the same handle<o:p></o:p></span></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><div><p class=MsoNormal>I'm using the C ESL events api.<o:p></o:p></p><div><p class=MsoNormal>I have one threads that continuously checks for updates using&nbsp;esl_recv_event()<o:p></o:p></p></div><div><p class=MsoNormal>I have another thread that sometimes needs to inject commands, that uses&nbsp;esl_send_recv() on the same handle.<o:p></o:p></p></div><div><p class=MsoNormal>It looks like on occasion, both get stuck and stop receiving events.<o:p></o:p></p></div><div><p class=MsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=MsoNormal>Is it possible for two threads to access the handle? maybe I should open two connections to freeswitch esl? or use esl_send_recv_timed()?<o:p></o:p></p></div><div><p class=MsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=MsoNormal>stack trace:<o:p></o:p></p></div><div><div><p class=MsoNormal>#0 &nbsp;0xb6f3f974 in __lll_lock_wait () from /lib/arm-linux-gnueabi/libpthread.so.0<o:p></o:p></p></div><div><p class=MsoNormal>#1 &nbsp;0xb6f39858 in pthread_mutex_lock () from /lib/arm-linux-gnueabi/libpthread.so.0<o:p></o:p></p></div><div><p class=MsoNormal>#2 &nbsp;0x000f2f2c in esl_mutex_lock (mutex=&lt;optimized out&gt;) at src/esl_threadmutex.c:200<o:p></o:p></p></div><div><p class=MsoNormal>#3 &nbsp;0x000efb70 in esl_recv_event (handle=0x11b67c, check_q=0, save_event=0xb6c47da4) at src/esl.c:1262<o:p></o:p></p></div><div><p class=MsoNormal>#4 &nbsp;0x0001ebbc in EslHandler::initThread (this=0x11b670) at eslHandler.cpp:95<o:p></o:p></p></div><div><p class=MsoNormal>#5 &nbsp;0x0001ec88 in EslHandler::entryPoint (eslHandler=0x11b670) at eslHandler.cpp:110<o:p></o:p></p></div><div><p class=MsoNormal>#6 &nbsp;0xb6f36b04 in start_thread () from /lib/arm-linux-gnueabi/libpthread.so.0<o:p></o:p></p></div><div><p class=MsoNormal>#7 &nbsp;0xb6d25a2c in ?? () from /lib/arm-linux-gnueabi/libc.so.6<o:p></o:p></p></div><div><p class=MsoNormal>#8 &nbsp;0xb6d25a2c in ?? () from /lib/arm-linux-gnueabi/libc.so.6<o:p></o:p></p></div><div><p class=MsoNormal>Backtrace stopped: previous frame identical to this frame (corrupt stack?)<o:p></o:p></p></div><div><p class=MsoNormal>(gdb) thread 1<o:p></o:p></p></div><div><p class=MsoNormal>[Switching to thread 1 (Thread 0xb6c4a000 (LWP 3020))]<o:p></o:p></p></div><div><p class=MsoNormal>#0 &nbsp;0xb6d17c04 in poll () from /lib/arm-linux-gnueabi/libc.so.6<o:p></o:p></p></div><div><p class=MsoNormal>(gdb) info stack<o:p></o:p></p></div><div><p class=MsoNormal>#0 &nbsp;0xb6d17c04 in poll () from /lib/arm-linux-gnueabi/libc.so.6<o:p></o:p></p></div><div><p class=MsoNormal>#1 &nbsp;0x000ef92c in esl_wait_sock (sock=&lt;optimized out&gt;, ms=&lt;optimized out&gt;, flags=&lt;optimized out&gt;) at src/esl.c:929<o:p></o:p></p></div><div><p class=MsoNormal>#2 &nbsp;0x000ef988 in handle_recv (handle=0x11b67c, data=0x11b91c, datalen=65535) at src/esl.c:1230<o:p></o:p></p></div><div><p class=MsoNormal>#3 &nbsp;0x000efc84 in esl_recv_event (handle=0x11b67c, check_q=&lt;optimized out&gt;, save_event=0x12c120) at src/esl.c:1323<o:p></o:p></p></div><div><p class=MsoNormal>#4 &nbsp;0x000f0ba4 in esl_send_recv_timed (ms=0, cmd=&lt;optimized out&gt;, handle=0x11b67c) at src/esl.c:1554<o:p></o:p></p></div><div><p class=MsoNormal>#5 &nbsp;esl_send_recv_timed (handle=0x11b67c, cmd=&lt;optimized out&gt;, ms=0) at src/esl.c:1521<o:p></o:p></p></div><div><p class=MsoNormal>#6 &nbsp;0x0001f2e0 in EslHandler::sendAtCommand (this=0x11b670, atCmd=...) at eslHandler.cpp:204<o:p></o:p></p></div><div><p class=MsoNormal>#7 &nbsp;0x0001f86c in EslHandler::getImsiFromSim (this=0x11b670) at eslHandler.cpp:262<o:p></o:p></p></div><div><p class=MsoNormal>#8 &nbsp;0x0001450c in FsControl::checkMessages (this=0x11b2a0) at fsControl.cpp:435<o:p></o:p></p></div><div><p class=MsoNormal>#9 &nbsp;0x000124cc in FsControl::handleEslCustomEvent (this=0x11b2a0, mapEventReceived=...) at fsControl.cpp:376<o:p></o:p></p></div><div><p class=MsoNormal>#10 0x0000f334 in FsControl::handleEslEvent (this=0x11b2a0, mapEventReceived=...) at fsControl.cpp:226<o:p></o:p></p></div><div><p class=MsoNormal>#11 0x0000e7a8 in FsControl::OnWaitHandle (this=0x11b2a0, whp=0x13aea8, data=...) at fsControl.cpp:140<o:p></o:p></p></div><div><p class=MsoNormal>#12 0x000d230c in os::Schedualed::OnEvent (this=0x11b2a0, event=0x13aea8, data=...) at cpp/os.cpp:1578<o:p></o:p></p></div><div><p class=MsoNormal>#13 0x000cd1d0 in os::Schedualer::mainloop (this=0x11b348, exitOnNoneManaged=false) at cpp/os.cpp:446<o:p></o:p></p></div><div><p class=MsoNormal>#14 0x000161e0 in main (argc=3, argv=0xbea16904) at fsControl.cpp:603<o:p></o:p></p></div></div><div><p class=MsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=MsoNormal><o:p>&nbsp;</o:p></p></div></div></div></body></html>