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

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to