Re: Multhithreading internals in GTK+



Hi Vish,

2009/12/2 Vishwanath Venkatesan <venkates cs columbia edu>:
> I am trying to understand the  internals of threading in GTK+-2.0. From my
> understanding there are threads generated with GTK+ functions (ex. Opening a
> file-dialog) even without explicit  threading.

That's not correct. Gtk+ is a single-threaded system with an event loop.

gtk_main() sits in a loop getting events from various sources and
dispatching them to various scraps of code according to the event
type. Each scrap of code will do a tiny bit of processing and then
return back to the main loop again. Everything runs in the same
thread.

You can have nested main loops: if you pop up a window, it can be a
programming convenience to have another main loop to handle the
interaction for that dialog, but it's not required. Again, the inner
main loop runs in the same thread.

If you want to have several threads in your application, it's usually
best to only have one of them doing all the gtk calls. You can use
some parts of glib to get worker threads to send safe messages to the
main thread.

John


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