Hi Stefano

Would it be possible for you to implement a reference counter in the object
that your nua handle magic is pointing to?
You would need to be sure to increment/decrement it in a thread-safe way of
course.
Then, only free the nua handle magic when your reference counter has reached
0.

This would be similar to what Sofia does for the memory associated with the
nua handles themselves.

Best regards,
-Dan


-----Original Message-----
From: Stefano Sabatini [mailto:ssabat...@reilabs.com] 
Sent: 27 April 2010 10:06
To: sofia-sip-devel Mailing List
Subject: [Sofia-sip-devel] Safe free of nua_magic_t in a multithreaded
application

Hi all,

I'm facing this problem in a multithreaded application, with a thread
running the sofia sip event callback (thread A), and another thread (thread
B) managing the deallocation of the nua handles.

The problem is that when a nua handle is destroyed by thread B, thread A may
still be processing a message associated to the nua handle and the
corresponding nua handle magic which is being destroyed by thread B.

Currently I'm simply skipping the destruction of the nua handle magic, which
results in a leak. If I destroy the nua handle magic in thread B this may
result in an occasional crash when thread A tries to access the nua handle
magic which is being destroyed.

A possible solution would be to delay the destruction of the nua handle
magic after the corresponding nua handle has been destroyed, this way I
would be pretty sure that the thread A is not anymore processing messages
associated to the destroyed nua handle, but as you may guess this may not
work in case of slowdowns.

So the problem seems that when I'm processing nua handle+magic in thread A
I'm not sure if nua handle+magic still exist.

I wonder if it would be possible to make nua send a final message to the nua
thread *after* nua_handle has been destroyed with
nua_handle_destroy() or a corresponding command. If this would be possible,
then I could safely destroy the handle in thread B, and let thread A destroy
the nua handle magic in thread A when this final message is received.

Can you say if this would be feasible, or suggest a valid solution to the
problem?

TAI, regards.

----------------------------------------------------------------------------
--
_______________________________________________
Sofia-sip-devel mailing list
Sofia-sip-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel


------------------------------------------------------------------------------
_______________________________________________
Sofia-sip-devel mailing list
Sofia-sip-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel

Reply via email to