Re: GSlice: g_thread_init() must be called before all other GLib functions;



On Tue, Jun 19, 2007 at 03:53:30PM +0200, John Zoidberg wrote:
I get the following error message when running my GTK app:

GSlice: g_thread_init() must be called before all other GLib functions;
memory corruption due to late invocation of g_thread_init() has been
detected; this program is likely to crash, leak or unexpectedly abort
soon...


I read here<http://blogs.gnome.org/timj/2007/01/02/28122006-g_slicedebug-blocks/>that
the correct workaround is to call
g_thread_init(NULL).

This is a bit taken out of context.  This is not so much of
a workaround as something you always have to do when you use
threads.  And you have to do this very early.  And the
problem was that even if people were told to do this very
early, they didn't (because it had used to work and because
sometimes the responsibility was not clear) -- and then
GSlice came and made programs that did not call
g_thread_init() early actually break.

If you do not use threads, nothing of this concerns you.

However, when I try to do that I get an "undefined reference to
g_thread_init" error.

And this happens even if I include glib.h.

I did a grep on the header files I have in /usr/include and got this:
glib-1.2/glib.h:void   g_thread_init   (GThreadFunctions       *vtable);
glib-2.0/glib/gthread.h:void    g_thread_init   (GThreadFunctions
*vtable);
glib-2.0/glib/gthread.h:void    g_thread_init_with_errorcheck_mutexes
(GThreadFunctions* vtable);
glib-2.0/glib/gthread.h:#define g_thread_init(vtable)
g_thread_init_with_errorcheck_mutexes (vtable)
glibmm-2.4/glibmm/thread.h:  g_thread_init(vtable);
grep: warning: lua50/lua: recursive directory loop

So I added the corresponding headers:
#include <glib-2.0/glib/gthread.h>
#include <glib-1.2/glib.h>

Well, this is extremely fishy.  Are you trying to use GLib
1.2 and 2.0 simultaneously in one program?  This will not
work.

After some printf debugging, I traced the origin of the warning to the
creation of a filechooser button.
And when I create a new GTK project with Anjuta+Glade2 and place a
filechooser button, I do indeed always get this warning.

How can I get rid of this warning the correct way?

For start, get rid of everything GLib-1.2-ish.  This itself
can fix the problems.  Or maybe not.

Where am I supposed to place the g_thread_init() call?

If you use threads, or something you use uses threads, then
before any other GLib call, or call to something that uses
GLib (for instance to Gtk+).  The very first line of main()
can be a good place.

And you have to add `gthread-2.0' to the list of pkg-config
packages your program depends on (have no idea how to do
this in Anjuta or Glade, but it typically should appear in
an argument of PKG_CHECK_MODULES() in configure.ac at the
end).

Yeti

--
http://gwyddion.net/



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