[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: Gtk+ and multithreating
- From: Chris Vine <chris cvine freeserve co uk>
- To: Michelle Konzack <linux4michelle freenet de>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Gtk+ and multithreating
- Date: Wed, 16 May 2007 21:32:39 +0100
On Wed, 2007-05-16 at 16:44 +0200, Michelle Konzack wrote:
> Am 2007-05-14 22:22:34, schrieb Chris Vine:
> > Pass the callbacks representing the events concerned to the main program
> > loop using g_idle_add(). Make sure the callbacks return FALSE.
> > g_idle_add() is thread safe, provided that you have initialised glib
> > with g_thread_init().
> >
> > Chris
> ------------------------- END OF REPLIED MESSAGE -------------------------
>
> Forgive me if I do not understand this...
> Do you have a short exanple?
>
> For the phtreads I have only copied an example-sniplet
> and modified a bit and it was just working... :-)
The documentation is here:
http://developer.gnome.org/doc/API/2.0/glib/glib-The-Main-Event-Loop.html#g-idle-add
The idea is that you call g_idle_add() in your worker thread with a
callback (function pointer and data) which you want to execute in the
main program (GUI) loop.
A simple example would be to call:
g_idle_add((GSourceFunc)g_print, "Hello\n");
If you call this in the worker thread, it will print "Hello" in the GTK+
main program thread (you must have called g_thread_init(NULL) first).
It is the standard way of passing events to the GUI thread.
Incidentally, instead of using pthreads, you can use the platform
independent GThread implementation. See:
http://developer.gnome.org/doc/API/2.0/glib/glib-Threads.html
Chris
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]