[Freeswitch-users] esl_recv_event() from two threads on the same handle

Grant Bagdasarian GB at cm.nl
Tue Aug 5 15:16:45 MSD 2014

I once had the same problem, but with the .NET version of the ESL library.
I was told on this mailing list to not have multiple Threads access the same ESLconnection object.

In .NET I’d get a AccessViolationException.

Having two connections to FS ESL would probably be better; one for receiving, the other for sending commands.
The connection for receiving events could then also distribute the events to all other components in your program which require these events.
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.

Hope this helps.

From: freeswitch-users-bounces at lists.freeswitch.org [mailto:freeswitch-users-bounces at lists.freeswitch.org] On Behalf Of Shlomi Agiv
Sent: Tuesday, August 5, 2014 10:14 AM
To: FreeSWITCH Users Help
Subject: [Freeswitch-users] esl_recv_event() from two threads on the same handle

I'm using the C ESL events api.
I have one threads that continuously checks for updates using esl_recv_event()
I have another thread that sometimes needs to inject commands, that uses esl_send_recv() on the same handle.
It looks like on occasion, both get stuck and stop receiving events.

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()?

stack trace:
#0  0xb6f3f974 in __lll_lock_wait () from /lib/arm-linux-gnueabi/libpthread.so.0
#1  0xb6f39858 in pthread_mutex_lock () from /lib/arm-linux-gnueabi/libpthread.so.0
#2  0x000f2f2c in esl_mutex_lock (mutex=<optimized out>) at src/esl_threadmutex.c:200
#3  0x000efb70 in esl_recv_event (handle=0x11b67c, check_q=0, save_event=0xb6c47da4) at src/esl.c:1262
#4  0x0001ebbc in EslHandler::initThread (this=0x11b670) at eslHandler.cpp:95
#5  0x0001ec88 in EslHandler::entryPoint (eslHandler=0x11b670) at eslHandler.cpp:110
#6  0xb6f36b04 in start_thread () from /lib/arm-linux-gnueabi/libpthread.so.0
#7  0xb6d25a2c in ?? () from /lib/arm-linux-gnueabi/libc.so.6
#8  0xb6d25a2c in ?? () from /lib/arm-linux-gnueabi/libc.so.6
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) thread 1
[Switching to thread 1 (Thread 0xb6c4a000 (LWP 3020))]
#0  0xb6d17c04 in poll () from /lib/arm-linux-gnueabi/libc.so.6
(gdb) info stack
#0  0xb6d17c04 in poll () from /lib/arm-linux-gnueabi/libc.so.6
#1  0x000ef92c in esl_wait_sock (sock=<optimized out>, ms=<optimized out>, flags=<optimized out>) at src/esl.c:929
#2  0x000ef988 in handle_recv (handle=0x11b67c, data=0x11b91c, datalen=65535) at src/esl.c:1230
#3  0x000efc84 in esl_recv_event (handle=0x11b67c, check_q=<optimized out>, save_event=0x12c120) at src/esl.c:1323
#4  0x000f0ba4 in esl_send_recv_timed (ms=0, cmd=<optimized out>, handle=0x11b67c) at src/esl.c:1554
#5  esl_send_recv_timed (handle=0x11b67c, cmd=<optimized out>, ms=0) at src/esl.c:1521
#6  0x0001f2e0 in EslHandler::sendAtCommand (this=0x11b670, atCmd=...) at eslHandler.cpp:204
#7  0x0001f86c in EslHandler::getImsiFromSim (this=0x11b670) at eslHandler.cpp:262
#8  0x0001450c in FsControl::checkMessages (this=0x11b2a0) at fsControl.cpp:435
#9  0x000124cc in FsControl::handleEslCustomEvent (this=0x11b2a0, mapEventReceived=...) at fsControl.cpp:376
#10 0x0000f334 in FsControl::handleEslEvent (this=0x11b2a0, mapEventReceived=...) at fsControl.cpp:226
#11 0x0000e7a8 in FsControl::OnWaitHandle (this=0x11b2a0, whp=0x13aea8, data=...) at fsControl.cpp:140
#12 0x000d230c in os::Schedualed::OnEvent (this=0x11b2a0, event=0x13aea8, data=...) at cpp/os.cpp:1578
#13 0x000cd1d0 in os::Schedualer::mainloop (this=0x11b348, exitOnNoneManaged=false) at cpp/os.cpp:446
#14 0x000161e0 in main (argc=3, argv=0xbea16904) at fsControl.cpp:603

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20140805/4968fb94/attachment.html 

Join us at ClueCon 2016 Aug 8-12, 2016
More information about the FreeSWITCH-users mailing list