Re: Thread-generated signals



Michael Ekstrand wrote:
On Tue, 14 Mar 2006 14:04:11 +0100
Nicolas George <nicolas george ens fr> wrote:

I mean, I have a thread running the Gtk+ main loop of a GUI, and a
second thread doing a very specific work (using libseex and libao, in
my case). When some points of the work of the second thread are
reached, I want some changes in the GUI. I could just use a pair of
gdk_threads_enter() / gdk_threads_leave() and do the update in the
working thread, but I do not find that solution satisfactory. I would
rather have the working thread to just send some sort of signal, and
let the GLib main loop call a callback in the GUI thread as soon as
it is in a safe state. Is there a good way to do this?
[...]
gdk_threads_enter();
g_idle_add(callback, data); /* may need some macros here; I'm a
                             * PyGTK/GTKmm guy, so the C stuff
                             * isn't my forte */
gdk_threads_leave();

Note; no need to hold the gdk lock for this; g_idle_add()
(along with all the apis that operate on the GMainContext
data struct) is safe to call as is.

Cheers,
                     -Tristan



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