Quitting a child thread's GMainLoop



I'm developing a multi-threaded GLib application.  Each thread,
including the main thread, has its own GMainLoop for polling input sources.

This works well, but I'm having trouble finding an elegant way to
shutdown the child threads from the main thread, because the "main
loops" I want to quit live in the child threads.  Is there any way I can
quit the main loop of a child thread from a parent thread?  Can a parent
thread somehow access the "main loop context" of a child thread and tell
it to quit somehow?

I know I can pass in data (such as the address of a gboolean "shutdown"
variable) to the g_thread_create call(), but how does the child thread
check this flag when running in a GMainLoop?  It seems a bit silly and
wasteful to create an idle GSource just to check a quit flag -- but is
that the only way to do it?

Thanks.
-Tony



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