Re: threads & gnome




"Christopher T. Lansdown" <lansdoct@screech.cs.alfred.edu> writes:

> Hi,
> 	I'm currently writing a Gtk+ based multi-threaded app.  Using Gtk
> in multi-threaded mode (g_thread_init() & using gdk_threads_enter()
> gdk_threads_leave()) is working well so far except for some parts of
> gnome.  Now, I realize that this doesn't have much applicability to gtk
> exactly, but I was hoping that people could help me to figure out where to
> look for the problem.
> 	The problem: when I call g_thread_init() at the beginning of my
> app, my program crashes whenever a gnome menu is accessed (i.e. when it is
> clicked on but before it pops up).  The toolbar, canvas, and other gnome
> and gtk widgets work fine.  When I don't call g_thread_init(), the menu
> works just fine.  In neither case have any new threads been started, the
> only difference is calling g_thread_init().  What could g_thread_init() be
> doing that would screw up the gnome ui library that much?

I can't reproduce that here. Can you provide a small test
case?

> 	On a related note, is there anything that the gnome libraries
> would have to do in order to be thread safe when Gtk is thread safe, or
> should just wrapping all gnome calls in gdk_threads_enter() and
> gdk_threads_leave() be sufficient?

Yes, that should be OK. I made a few small changes to the
GNOME libraries at one point so that the GTK+ lock would
be reacquired in timeouts and callbacks within libgnomeui
as necessary when GLib was initialized for threads.
Hopefully, new timeouts and/or idle functions haven't been
added since then.

> 	Oh, the other thing, is gtk_main really supposed to be called as:
> gdk_threads_enter();
> gtk_main();
> gdk_threads_leave();

Yes it is. Or, you could directly use the g_main_* functionality
from GLib, which is thread safe without explicit locking.
 
> Or should the threads calls be omitted?  Should gdk_threads_enter() be
> called around all gtk code used in the main thread?

Yes. All GTK+/GDK calls must be called inside a threads_enter()
threads_leave() pair.

> The FAQ was a bit
> cryptic on this point, since its example multi-threaded code was
> single-threaded.

> P.S. please cc me on all replies, as I am unfortunately not on this list
> (I'm on gtk-app-devel, but this question seems more appropriate for this
> forum.  I apologize for the inconvenience).

Actually, this would be more appropriate for gnome-devel-list,
gtk-app-devel-list or gtk-list, since it really doesn't have anything
do with the development of GTK+ itself.

Regards,
                                        Owen



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