Re: Threads and Gtk

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

 



On Thu, 2012-10-11 at 08:23 -0400, Martin Sivak wrote:
> Hi,
> 
> we have got a lot of information while debugging #862801 so this email is just a quick summary about how we are supposed to use Gtk in threaded environment. As you might know - GLib itself is threadsafe but Gtk is not.
> 
> According to the Gtk team, the gdk_threads_enter/leave pair should not be used at all (and they have apparently discouraged usage of it since early releases of Gtk2). Moreover in the current Gdk docs (http://developer.gnome.org/gdk3/stable/gdk3-Threads.html#GDK-THREADS-ENTER:CAPS) those functions are now marked as deprecated.
> 
> The preferred way (and now the only way) is to use g_idle_add (GLib.idle_add) with a callback method to schedule GUI changes. The callback method will then get called by the Gtk main loop so no locking is needed (and GLib.idle_add performs none). But that is also the reason why everything Gtk related must be done from the mainloop thread either directly or via idle_add.
> 
> If we need to wait for the callback's response (Dialog?), we should probably use Queue.Queue's .put (in the callback) and .get (at the place where we need the response) as Queue properly blocks while waiting for data. I have written two decorators which will make any function decorated with it to be executed in the main loop regardless of the thread it was called in.
> 
> This all means that gdk_threaded context manager should not be used anywhere anymore and I am currently trying to update the code to follow this rule. You can check the decorators (gui/utils.py) and changes (still work in progress) in my personal threading branch at:
> 
> http://fedorapeople.org/cgit/msivak/public_git/anaconda.git/?h=threading
I've tested the patches from this branch in various use cases that are
known to be problematic and hit no hang and no unexpected termination or
traceback. I believe these patches are worth sending to
anaconda-patches, reviewing, more testing and getting them to F18.

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux