[libnice] multithread g_main_loop_quit ad remove agent

Youness Alaoui kakaroto at kakaroto.homelinux.net
Mon Jul 7 01:39:12 PDT 2014


Hi,

Just a note about the issue of removing a source after it was triggered but
not yet dispatched, although I'm not sure this will help in your case, you
should always call the following code in a source callback function :
if (g_source_is_destroyed(g_main_current_source()) {
  return;
}

I believe libnice already checks that before calling the callback, so you
may not need to. It's a nice trick to know though. See the documentation
for g_source_is_destroyed.

Youness.



On Mon, Jul 7, 2014 at 3:17 AM, Philip Withnall <philip at tecnocode.co.uk>
wrote:

> Hi,
>
> 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
> crash.
>
> 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.
>
> Philip
>
> 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
>
>
> _______________________________________________
> nice mailing list
> nice at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/nice
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/nice/attachments/20140707/10e9bf9e/attachment.html>


More information about the nice mailing list