Re: Multithreaded gtk apps



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 1/14/2013 10:02 AM, Emmanuele Bassi wrote:
> the documentation says:
> 
> GTK+ is "thread aware" but not thread safe — it provides a global
> lock controlled by gdk_threads_enter()/gdk_threads_leave() which
> protects all use of GTK+. That is, only one thread can use GTK+ at
> any given time.
> 
> You must call gdk_threads_init() before executing any other GTK+
> or GDK functions in a threaded GTK+ program.
> 
> [...]
> 
> Unfortunately, all of the above documentation holds with the X11 
> backend only. With the Win32 backend, GDK and GTK+ calls should not
> be attempted from multiple threads at all. Combining the GDK lock 
> with other locks such as the Python global interpreter lock can be 
> complicated. --
> http://developer.gnome.org/gdk3/stable/gdk3-Threads.html

It doesn't even seem to hold there.  If I understand what's going on
here, some of the gtk code is placing a message in the queue and
waiting for the main loop to dispatch it.  When the main loop in the
other thread wakes up, it first tries to reacquire the gdk lock, which
deadlocks since the background thread is already holding it.

> you can raise the dialog from the main thread, and use a condition
> and a shared variable to notify the thread with the user-supplied
> value.

That feels a little dirty.  Can't I use a signal or closure to have
the main loop execute then return the value?



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (MingW32)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJQ9CD5AAoJEJrBOlT6nu75p4EIAMjYGL98TjteooR/usx/ToQH
Ix2jsLgrATkArJVfa97sL13OeSlKQUZfOXDsI5ztkt+iJXh3YIhNKxyxszToYlIm
XJJLwywj64eeHi3ihNQ6QzGdGXnUfg+2Z969IHLp8V5snUvoQKEj0vkG/KwqEbPA
lH1mNumtLRASguzwIuv0aANWFLdJxvSECscRLn3J8EvSwvvHuEveSJZAJ0oJaMrk
KJ37fNNSvOn1RfWnBVmD2gbcyNZDjg3YXqhaEp2cREGW7xcUf2QXwkv+MXUu+asa
GfkkyhJLNsqROCft04tlWgxoTjg4ecPOTH454VG44NKpNAcD4Eza7mZtiOesoJo=
=4b/x
-----END PGP SIGNATURE-----


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