Re: Application suddenly stuck at startup




Hey,

On Sat, Mar 2, 2013 at 2:54 AM, Jonathan Ballet <jon multani info> wrote:
 Re: Clarification of GTK/GDK locking pre GTK 4.0
    http://thread.gmane.org/gmane.comp.gnome.gtk+.general/24817/focus=24834

Eh.
I've been reading the whole thread, as well as other threads on the group, and I'm not sure the situation is clarified in my head... :-)
Some says Gdk.thread_* functions are deprecated and everything touching Gtk should run in the main thread, some says GLib.idle_add is running in the main thread and it's OK but maybe not...

I think I was able to gain a some understanding from that discussion. What I got from it is the deprecation is only for gdk_threads_enter/leave, not threading functions in general. Instead of using enter/leave, use gdk_threads_add_* functions to queue up a callbacks that interact with GTK/GDK. Internally these just wrap your callback in enter/leave anyhow. And enter/leave won't go away until GTK 4, they will always remain functional for the lifetime of GTK 3.

All of this seems somewhat irrelevant at least in the current state of the code base if you are writing a single threaded app. So unless you want to intact with GTK from a thread other than the main one, you never need to call gdk_threads_init. And if you don't call gdk_threads_init, gdk_threads_enter/leave are a no-op anyway and a lock is not even used.

So, say my application is not using any threads (it doesn't create threads on its own):

* should I still call Gdk.theads_init()?

No it would not be needed, you only need to do this if you want to interact with GTK from a thread other than the main one. You can still create and use threads in your app without this, you just can not safely interact with GTK from those threads.
 
* is it safe to use GLib.idle_add() & co? If no, in which context is it unsafe?

Should be fine.
 
* must I use Gdk.threads_add_* & co? If yes, in which context must I use them?

I don't think it will make a difference unless you also called Gdk.threads_init().

* is it safe to assume that all my code is running in the main thread, and that I can skip using Gdk.threads_* API and that I also don't have to use GLib.idle_add API to schedule modifications to my Gtk widgets? [2]

I think so.

[2]: in lot of places, my application was using lines like:

   GLib.idle_add(gtk_entry.set_text, "foo bar")

If GDK threading is enabled, I think it should be:
Gdk.threads_add_idle(GLib.PRIORITY_DEFAULT, gtk_entry.set_text, "foo bar")

Hope this helps,
-Simon




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