Re: Gnome/Gtk and thread safety



Maciej Stachowiak <mjs eazel com> writes: 
> 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?
> 

Assume it's a global variable, or a variable inside some other object
inside some other object which is a global variable.

A common case might be this code:

 static GtkWidget *dialog = NULL;
 if (dialog == NULL)
   dialog = gtk_dialog_new ();

You have to avoid the race; otherwise you'll get bizarre bugs
eventually, pretty guaranteed.

Havoc





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