Re: Gnome/Gtk and thread safety



"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. Needless to say, changing that
would result in all objects in all existing apps being leaked. So
you'd have to introduce gtk_everywidget_new_with_extra_refcount() and
tell people they have to use those variants for threadsafety. Deluxe
yuck.

We very much would like to have the threadsafety, but it can't be
retrofitted well. I believe this is why it hasn't been done. Any
number of people have suggested "GTK should be threadsafe" but no one
has ever gone through and made a concrete proposal that thinks through
this type of issue and shows how e.g. GtkWidget would end up looking.

Havoc







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