GNOME Bugzilla – Bug 318851
g_thread_init should not be called if the glib threads system is already initialized
Last modified: 2009-08-15 18:40:50 UTC
Recently i run in a problem, which could be solved with a Gtk.initCheck functionality in java-gnome. I have a swing program which uses several threads, and one of the threads fire up a gtk toplevel window. The problem starts when i use the GNU Classpath to run my program. As it uses gtk peers, when the java-gnome call its own Gtk.init method i will get an error message that Gtk is already initialized and the program quits. I cant get rid of the Gtk.init from the java-gnome thread because sometime i use the sun jvm to run the program - which obviously needs the Gtk.init call. I could check for what kind of jvm i use but that would be rather ugly. The actual error message when using jamvm is as follows: GThread-ERROR **: GThread system may only be initialized once. aborting...
Created attachment 53471 [details] [review] first shot implementation of Gtk.initCheck This is a first quick implementation which just works for me atm. This patch doeas not call g_thread_init and does not register gdk_threads_enter for atexit.
I realized that the real problem came from g_thread_init being called once from gnu classpath and once from Gtk.init(). The following patch should fix this issue: --- src/jni/org_gnu_gtk_Gtk.c 13 Sep 2005 09:06:32 -0000 1.19 +++ src/jni/org_gnu_gtk_Gtk.c 16 Oct 2005 18:36:14 -0000 @@ -48,7 +48,8 @@ * deadlock behaviour. */ - g_thread_init(NULL); + if (!g_thread_supported ()) + g_thread_init(NULL); /* gdk_threads_init(); */ /*
Changing Summary to match the actual problem and marking initial patch as obsolete.
Thanks for the patch. It has been applied to CVS HEAD.