Re: Thread-generated signals



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?

Wouldn't it work to just register your callback as an idle handler?
Have it return FALSE, so it doesn't get run again, but it will be run
in the main loop.

Just do

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();

You could wrap this in a wrapper function call_later_in_main_loop()
that does the thread entering/leaving for you automatically.

If this is for updating a progress bar or something, your progress bar
will get updated whenever the main loop doesn't have any other events
to deal with.

- Michael

-- 
mouse, n: a device for pointing at the xterm in which you want to type.
                -- Fortune



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