Re: Clarification of GTK/GDK locking pre GTK 4.0

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

 



hi;

On 14 September 2012 16:53, Paul Davis <paul@xxxxxxxxxxxxxxxxxxxxx> wrote:
>
>
> On Fri, Sep 14, 2012 at 11:11 AM, Emmanuele Bassi <ebassi@xxxxxxxxx> wrote:
>
>     [ .... a lot of very confusing stuff ... ]

*really*?

this stuff has been known for the past 5 years at least, even before
we had gdk_threads_add_* - it's the reason why those functions were
added in the first place. the documentation of those functions also
makes it clear what they do, why, and even how.

> are you saying that g_idle_add() is not thread-safe?

no, I'm not saying that *at* *all*.

the callback that you pass to g_idle_add() and g_timeout_add() and
that is invoked from within the same GMainContext (usually the default
one, unless you start playing with GSource directly), though, has to
be called with the GDK lock held to avoid code acquiring the GDK lock
in different threads and running at the same time.

> because if it IS
> threadsafe, and the rest of program either
>
>    (a) only uses g_idle_add() to get work done in the main context
> OR
>    (b) religiously uses enter/leave to do GDK/GTK work in other threads

it is *not* an exclusive OR: it can happen that both conditions are
valid at the same time. for those cases, GDK provides
gdk_threads_add_*, which guarantees not only that your callback gets
executed under the same GMainContext as the rest of GDK, but also with
the GDK lock held.

especially in the case of libraries gdk_threads_add_* should be used
to allow applications still using the gdk_threads_enter/leave pair of
functions to keep working.

as I said elsewhere in the thread: if you *know* you or your
dependencies are not using gdk_threads_enter() and gdk_threads_leave()
inside a separate thread (i.e. if neither you nor your dependencies
are acquiring the GDK lock directly) then you can use g_idle_add() and
g_timeout_add() because all the code calling GDK and GTK+ API will be
executed in the same thread. if you don't know, don't care, or can't
change your code, then use gdk_threads_add_* for the entire duration
of the GTK+ 2.x and 3.x API series.

ciao,
 Emmanuele.

-- 
W: http://www.emmanuelebassi.name
B: http://blogs.gnome.org/ebassi/
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
https://mail.gnome.org/mailman/listinfo/gtk-list


[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux