Re: handlers for g_timeout_add and g_idle_add different threads?
- From: Al Hooton <al hootons org>
- To: Tim Evans <t evans aranz com>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: handlers for g_timeout_add and g_idle_add different threads?
- Date: Wed, 08 Dec 2004 07:45:41 -0800
Tim, and all:
Thanks for the several replies I got to this question, the information
was exactly what I needed. This one simple detail seems to be left out
of the otherwise good documentation on main loops and idel/timeout
handlers in the GTK+ doc, hopefully this thread will get archived and
help some other folks.
On Wed, 2004-12-08 at 10:12 +1300, Tim Evans wrote:
Al Hooton wrote:
Quick question: I've read through all the stuff I can find on the glib
main loop support for timeout handlers and idle handlers, but there's a
simple question I have:
- Do either, or both. of these types of handlers get run in a different
thread, or are they run out of the mainloop/GMainContext the
g_timeout_add and g_idle_add routines were called in to add them?
They are both run inside the mainloop, so in the same thread that called
gtk_main(). This means that you shouldn't spend too much time in an
idle or timeout handler because it will block your gui.
Note that adding idle and timeout handlers is thread safe and can be
done from any thread without needing to acquire any locks first. I find
g_idle_add to be the best way for a worker thread to communicate with
the gui thread.
If you have called gdk_threads_init then idle and timeout handlers will
be run *without* the gdk thread lock and you will have to add
gdk_threads_enter/leave calls yourself if you are doing gui stuff.
] [Thread Prev