Re: Gnome/Gtk and thread safety
- From: Maciej Stachowiak <mjs eazel com>
- To: Havoc Pennington <hp redhat com>
- Cc: "Ryan C. Gordon" <icculus lokigames com>, gtk-devel-list gnome org
- Subject: Re: Gnome/Gtk and thread safety
- Date: 17 Oct 2000 20:13:13 -0700
Havoc Pennington <hp redhat com> writes:
> "Ryan C. Gordon" <icculus lokigames com> writes:
> > ...and making something thread safe is never a bad idea, is it?
> >
>
> I'm no threads expert, but my impression is that making GTK
> transparently threadsafe would break tons of API (or leave lots of
> legacy API that wasn't safe) and would cause a not insignificant
> performance hit.
>
> One of the nastiest problems is that for threadsafety you need
> everyone to own a reference to all objects they are using at all
> times; in this common code the application doesn't own a reference:
>
> GtkWidget *widget;
>
> widget = gtk_window_new ();
>
> You'd need to add the reference as follows:
>
> widget = gtk_window_new ();
> g_object_ref (widget);
>
> As you probably realize that doesn't work, there's a race condition
> where another thread can destroy the window (same thing applies to any
> widget). To avoid this condition you have to have all routines that
> return objects return a new reference.
We could take the classical Unix approach to fixing non-threadsafe
interfaces:
widget = gtk_window_new_r ();
:-)
Actually, I don't get why the code you posted above with
gtk_window_new has a race; how could another thread even have access
to the value of `widget' right after you assign it, let alone want to
sink or unref it?
- Maciej
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]