[pjsip] How to hangup a call - the right way ??
bennylp at pjsip.org
Thu May 22 04:31:55 EDT 2008
On Thu, May 22, 2008 at 4:23 AM, Turnaev Eugeny <turnaev at t72.ru> wrote:
>> > self.lock.acquire()
>> > try:
>> > call_info = py_pjsua.call_get_info(self.current_call)
>> > ... do some stuff
>> > finally:
>> > self.lock.release()
>> > So if i isolated every call to py_pjsua.call_get_info
>> > how can i came with
>> > pjsua_call.c Timed-out trying to acquire PJSUA mutex (possibly system has deadlocked) in pjsua_call_get_info()
>> > message in log?
>> Well that *exactly* is the problem, isn't it? Imagine two threads are
>> executing the same piece of code above, one thread comes from pjsip
>> callback and is holding pjsip mutex and trying to acquire self.lock
>> mutex, and the other thread is holding self.lock mutex and trying to
>> acquire pjsip mutex, you end up with deadlock. This is what the past
>> discussions were all about.
> I see. So self.lock only causes deadlock and protects nothing
> because of underlying mutexes in C.
> Should i better remove self.lock.acquire() on those chunks of code?
> I cant get - how should i deal with 2 threads calling pjsua functions,
> without knowing if there is an mutex acquired in C level?
pjsip is thread safe, you don't need to protect calls to pjsip with
mutex, this has been taken care of by the library.
> How to avoid deadlock from python?
I think the only solution is to not create any threads (both python
created threads and pjsua worker thread), hence there's no need to
have mutexes. I'm not sure how feasible this is to do, perhaps it will
be easier to do if you use a GUI toolkit and make everything event
based (then you just need to register a recurring timer event which
Another way is to serialize the mutex locking order as have been
discussed in the archive. But this requires exporting the private
acquire_call() function in pjsua_call.c (and pjsip_dlg_dec_lock()) to
> Is there a way to find out if pjsua already acquired lock on mutex (from python level)?
If the python code is called in the context of a pjsua callback, then
you know that pjsua lock has been acquired.
More information about the pjsip