Attaching an event source to a GMainLoop in a thread
- From: Braden McDaniel <braden endoframe com>
- To: gtk-app-devel-list gnome org
- Subject: Attaching an event source to a GMainLoop in a thread
- Date: Sun, 03 Dec 2006 05:26:43 -0500
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_event,
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:
#0 0x0000000000000000 in ?? ()
#1 0x0000003c9242cf6a in g_main_context_dispatch () from /lib64/libglib-2.0.so.0
#2 0x0000003c9242fd7d in g_main_context_check () from /lib64/libglib-2.0.so.0
#3 0x0000003c9243008a in g_main_loop_run () from /lib64/libglib-2.0.so.0
#4 0x000000000040b02d in operator() (this=0x6bec30) at ../.././../src/openvrml-gtkplug/main.cpp:322
#5 0x000000000040b099 in invoke (function_obj_ptr={obj_ptr = 0x6bec30, const_obj_ptr = 0x6bec30,
func_ptr = 0x6bec30, data = "0"}) at /usr/include/boost/function/function_template.hpp:136
#6 0x00002aaaac923d4f in boost::function0<void, std::allocator<boost::function_base> >::operator()
() from /usr/lib64/libboost_thread.so.2
#7 0x00002aaaac9238df in boost::thread_group::add_thread () from /usr/lib64/libboost_thread.so.2
#8 0x0000003c90006305 in start_thread () from /lib64/libpthread.so.0
#9 0x0000003c8f4cd62d in clone () from /lib64/libc.so.6
#10 0x0000000000000000 in ?? ()
I figure I'm probably missing something about the proper way to attach
the event source, perhaps related to the fact that I'm not doing this in
the main thread.
--
Braden McDaniel e-mail: <braden endoframe com>
<http://endoframe.com> Jabber: <braden jabber org>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]