Re: Attaching an event source to a GMainLoop in a thread
- From: Chris Vine <chris cvine freeserve co uk>
- To: gtk-app-devel-list gnome org
- Cc: Braden McDaniel <braden endoframe com>
- Subject: Re: Attaching an event source to a GMainLoop in a thread
- Date: Sun, 3 Dec 2006 19:05:33 +0000
On Sunday 03 December 2006 10:26, Braden McDaniel wrote:
I have a GMainLoop that I want to run in its own thread. But I seem to b
doing something horribly wrong with the event source I'm trying to
attach to it (all as part of the same thread). My thread function
includes this code:
        GMainContext * main_context = g_main_context_new();
        GMainLoop * main_loop = g_main_loop_new(main_context, false);
        GSource * quit = g_idle_source_new();
        g_source_set_callback(quit,
                              ::openvrml_player_command_channel_loop_quit_e
                              ::vent,
                              main_loop,
                              notify);
        guint source_id = g_source_attach(quit, main_context);
        g_assert(source_id != 0);
        g_main_loop_run(main_loop);
        g_source_unref(quit);
        g_main_loop_unref(main_loop);
        g_main_context_unref(main_context);
If I do not attach the event source, the code runs. But if I do attach
it, as above, I crash as soon as I start to run the main loop:
Wouldn't unreferencing main_context cause it to be freed?  (And does 
g_main_loop_run() increement the reference count of main_loop?  If not then 
unreferencing main_loop that will also destroy the main loop).  The call to 
g_source_unref() is correct (g_source_attach will increment the reference 
count of quit).
Chris
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]