Re: Multi-threaded light-server example



I had some more time to work on this today and I finally have a
working example of what I wanted to do thanks to this post:
http://gnome.soup.io/post/420776985/Philip-Withnall-Ensuring-functions-are-called-in
I have attached the example code in case anyone wants a way to do this
in the future.
Nick

On Fri, Aug 19, 2016 at 7:11 AM, Nick Deubert <ndeubert gmail com> wrote:
Ok, my GUPnP stack is running in one thread and for some of the action
callbacks I need to make an asynchronous call before I can call
gupnp_service_action_set() and gupnp_service_action_return(). So when the
asynchronous call comes back I am trying to make sure I call those return
functions from the context of the GUPnP thread. That is why for the sake of
the example I am spawning the new thread in the action callback.
Thanks,
Nick


Am 18.08.2016 11:25 nachm. schrieb "Jens Georg" <mail jensge org>:

Let's start the other way round: What is the actual problem you are
trying to solve?

After instrumenting my code and printing out the thread ids I don't
believe either of these solutions are correct. I knew it wouldn't be
as simple as that (I was crossing my fingers GMainContext did some
magic). Can anyone point me to a reference to understand
g_main_context_push_thread_default better?

I've been reading these, but applying them to this example code has
been confusing:
https://tecnocode.co.uk/2014/03/27/what-is-gmaincontext/
http://gnome.soup.io/post/420776985/Philip-Withnall-Ensuring-function
s-are-called-in

Any additional help would be greatly appreciated.

On Thu, Aug 18, 2016 at 10:36 AM, Nick Deubert <ndeubert gmail com>
wrote:

On Thu, Aug 18, 2016 at 10:14 AM, Nick Deubert <ndeubert gmail com>
wrote:

On Thu, Aug 18, 2016 at 3:28 AM, Jens Georg <mail jensge org>
wrote:

Everything! GUPnP-related has to be created in the worker
thread after
g_main_context_push_thread_default.

Otherwise half of your call-backs end up in main thread.


Thanks for the quick reply. Ok then is the attached code (which
seems
to work) correct?
Thanks for your help.

Or I suppose do I even need the main loop in main()? Is it as
simple
as just creating a GMainContext and pushing it before doing
anything
else? Would the attached code be safe?
Thanks.

Attachment: light-server.c
Description: Text Data



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]