GTK+'s current reliance upon pthreads for multithreading support is unacceptable for applications using other threading libraries. This patch obsoletes "gtk-rao-980910-0.patch.gz", and has been created against GTK+-1.1.1. Unlike the previous patch, which allowed additional support of thread libraries at compile time, this patch allows additional support of thread libraries at run time. A default implementation of pthreads is included and is enabled if --with-posix-threads is given to configure. Regardless of how configure is run, the ability to add thread libraries at run time is always allowed. Additional thread libraries can be added by implementing a GdkMutexFuncs and then passing a pointer to it to "void gdk_threads_set_funcs (GdkMutexFuncs *funcs)". typedef struct _GdkMutexFuncs { gpointer (*create_mutex) (gpointer init); void (*lock_mutex) (gpointer mutex); void (*unlock_mutex) (gpointer mutex); void (*destroy_mutex) (gpointer mutex); } GdkMutexFuncs; create_mutex is passed a gpointer which allows for "hinting" on what kind of mutex should be created. For example, in the pthreads implementation, create_mutex can be passed a (pthread_mutexattr_t *). If the gpointer passed is NULL, create_mutex should create a default mutex. However, in the case of certain thread libraries, such as Java, the init arg has a requirement that it not be NULL. The high level threading functions in gdkthreads now look like: void gdk_threads_set_funcs (GdkMutexFuncs *funcs); GdkMutexFuncs* gdk_threads_get_funcs (void); gpointer gdk_threads_init (gpointer init); void gdk_threads_enter (void); void gdk_threads_leave (void); void gdk_threads_deinit (void); gdk_threads_init returns a pointer to the created mutex, or NULL if the mutex could not be created. The "init" arg is passed directly to the create_mutex function. Exposing the returned mutex is extremely important for threading libraries (such as Java) where a mutex must have a proper context to be locked. If GTK+ is compiled with posix threading enabled, then a call to gdk_threads_init sets up a posix mutex, and there's no need to have previously called gdk_threads_set_funcs. The new API is designed to cause minimal change for applications using the current API. The standard threaded GTK+ app changes from: if (!gdk_threads_init ()) { fprintf(stderr, "Could not initialize threads\n"); exit(1); } [...] gdk_threads_enter (); gtk_main (); gdk_threads_leave (); to: if (!gdk_threads_init (NULL)) { fprintf(stderr, "Could not initialize threads\n"); exit(1); } [...] gdk_threads_enter (); gtk_main (); gdk_threads_leave (); Hopefully this patch has addressed all the concerns regarding the previous patch, and provides a flexible framework for dealing with other thread libraries. -- Paul Fisher * rao@gnu.org