[libnice] multithread g_main_loop_quit ad remove agent

Philip Withnall philip at tecnocode.co.uk
Mon Jul 7 00:17:17 PDT 2014


To ensure you receive no more callbacks for an agent, call
nice_agent_remove_stream() on all the agent's streams.

If you ever want to re-add the agent to the main loop, then using
nice_agent_attach_recv() with a null callback should work.

If, after trying the first option, you are still receiving the callback
after destroying the user, please provide us with a backtrace of the

A note about main loops: g_main_loop_quit() does not 'pause' the loop,
it stops it completely, *after* the current loop iteration has
completed. If T1 does not exit from g_main_loop_run() after you have
called g_main_loop_quit() from T2, then there is a bug in your code. You
are correct in thinking that pending sources will remain in the main
context after you have quit the main loop, and will be dispatched if the
loop is run again.


On Mon, 2014-07-07 at 08:40 +0200, Emanuele Bizzarri wrote:
> Hi,
> I'm using libnice in order to forward rtp data among users into a star
> topology network.
> When one user joins, he starts to send and receive data to and from
> other users.
> The server forwards packets among users.
> When he quit I have to remove and destroy the user reference.
> But how can I be sure that the nice_agent_attach_recv callback will not
> longer triggered?
> Sometimes my application crashes inside the callback after I've
> destroyed the user.
> I'm  using a dedicated thread (T1) to manage g_main_loop_run (it is a
> blocking function).
> Then user is destroyed by another thread (T2).
> I have tried to pause the loop using g_main_loop_quit (from T2) and wait
> T1 exiting from g_main_loop_run but without success.
> Probably there are pending sources/events already dispatched and when I
> rerun the loop they will be triggered.
> I've tried to call nice_agent_attach_recv with null callback before
> destroy the user, but the problem still remains.
> Can you help me please?
> Which is the correct way to add and remove an agent from a loop that
> manage multiple agents?
> Thank you in advance,
> Emanuele
> _______________________________________________
> nice mailing list
> nice at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/nice

-------------- 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/20140707/af04d085/attachment.sig>

More information about the nice mailing list