Re: handlers for g_timeout_add and g_idle_add different threads?

        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.

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