Re: more mainloops in more threads?
- From: Chris Vine <chris cvine freeserve co uk>
- To: Roberto -MadBob- Guido <bob4mail gmail com>
- Cc: gtk-list gnome org
- Subject: Re: more mainloops in more threads?
- Date: Tue, 01 Apr 2008 23:33:53 +0100
On Tue, 2008-04-01 at 23:17 +0200, Roberto -MadBob- Guido wrote:
> And, as I can understand, there is no way to manage different lists of
> handlers for different contexts (say: for different threads).
> I think Glib will need some low level revisions to match requirements for near
> future computation models...
You understand wrongly. You can have a separate glib main loop for any
thread, if you want.
Start the thread, get a GMainContext object (g_main_context_new()),
create a new GMainLoop with that context (g_main_loop_new()) and then
run the loop in that thread (g_main_loop_run()).
You can create main loop sources with g_idle_source_new(),
g_timeout_source_new(), g_child_watch_source_new() or a custom GSource
object and attach it to the GMainContext object you created, and it will
run in that thread.
glib is thread safe provide that you have called g_thread_init() first.
Read the documentation at
] [Thread Prev