[libnice] multithread g_main_loop_quit ad remove agent

Philip Withnall philip at tecnocode.co.uk
Mon Jul 14 00:41:47 PDT 2014


Hi,

On Mon, 2014-07-14 at 08:42 +0200, Emanuele Bizzarri wrote:
> I've followed your suggestions but the crash still happens.
> It is not simple produce a backtrace. I'm searching a way to get more logs.

I’m afraid there generally isn’t much we can do without a backtrace.

> Now I'm using the revision c2ccb1634542f7d9c2a87aa46af027e6df386dd8,
> because it seems the more stable on windows os (I've opened another
> thread about this).
> I've compared the code with version 0.1.7. I see that the code is
> similar but different.
> In both cases the receive callback is not protected by the mutex.
> ...
> /* Unlock the agent before calling the callback */
>       agent_unlock();
>       callback (agent, sid, cid, len, buf, data);
>       agent_lock();
> ...
> 
> Why do you make this choice?

Otherwise you could cause a deadlock by calling a libnice function on
that agent from the callback, I think. Olivier knows more about that
design decision than me though.

> In my case I have to destroy user_data (the last param of the callback)
> from my thread (T2), while the callback is running by a dedicated thread T1.
> But it seems technically possible that data can be destroyed when T1 is
> inside the callback.

If you want to destroy the user_data in a thread other than the one
running the main context you passed to nice_agent_attach_recv(), you
need to either:
 • implement your own locking on the user_data, or
 • (preferably) make it reference counted, and ensure the reference
counting functions are thread safe.

libnice guarantees that callbacks from nice_agent_attach_recv() will be
invoked in the thread running the GMainContext you passed to
nice_agent_attach_recv().

I suggest you use a more recent release than 0.1.5 (which contains
commit c2ccb163). There have been a number of fixes to threading and
event dispatching in 0.1.6 and 0.1.7. It would be more useful for
everyone if you used 0.1.7 and we fixed any issues which arose.

> Is it possible to keep agent locked during the callback, or it can
> produce deadlock or other undesired effect?

I don’t think this behaviour is going to change.

Philip
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 213 bytes
Desc: This is a digitally signed message part
URL: <http://lists.freedesktop.org/archives/nice/attachments/20140714/a5e87e35/attachment.sig>


More information about the nice mailing list