Re: gtk/gnome is thread safe ?

There has been some work on making gtk usable in multithreaded
applications.  It is not threadsafe as such though.

If you want to use gtk in a multithreaded application, add the following
statement to your main() function before the call to gtk_init (or a
gnome_init variant):

This will initialise the glib threading code.  You will also need to link
against the gthread library.  You can get the correct flags with:
  glib-config --libs gthread
  gtk-config --libs gthread

The gnome-config script does not understand the gthread argument (AFAIK).

When using gtk with multiple threads, you must aquire a lock before it is
safe to call any gdk/gtk functions.  It can be aquired with a call to

Note that if you are inside a signal handler, then the thread lock has
already been aquired (so trying to aquire it again would cause a
deadlock).  However, it is not aquired in timeout, idle or IO callbacks.

Gnome-libs OTOH, is not guaranteed to be completely safe even if you
follow these rules.  There are probably some timeout/idle functions that
should aquire the lock that don't, and bits of sensitive code that would
need to be protected by mutexes.  Other components, such as the metadata
code have been made multithread safe.  If things work for you, then that
is great, but don't be surprised if you get weird errors.

If you want to see gnome-libs thread safe, I am sure the developers will
take patches (as long as they don't add big overhead to single threaded
programs).  If you decide to take on this task, it is probably best to
keep the patches small, and have a number of patches that can be reviewed
on their own merit, rather than merging everything into one big patch.



On 10 Dec 1999, Eric Jung wrote:

> hi, wizards.
> I want to know wheter gtk/gnome is thread safe.
> Currently I think it's not thread safe at least about drawing.
> How can I use gtk/gnome in separated thread with using drawing fuctionalities.
> enjoy nice magic. :D

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