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

glib2.0 2.13/2.14 ***MEMORY-WARNING*** GSlice and g_thread_init()



        Hi there,

 GLib 2.10 and later permit allocation of "Memory Slices" [1].  But when
 using GLib from multiple threads, you MUST initialize the GLib thread
 system with g_thread_init().  If you don't, and your application uses
 memory slices (even indirectly), you might see such warnings:

***MEMORY-WARNING***: gconftool-2[15271]: 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...


 To repeat here some important part of the GLib documentation [2] for
 g_thread_init():
 - Most of the time you will only have to call g_thread_init (NULL).
 - g_thread_init() might only be called once. On the second call it will
   abort with an error. If you want to make sure that the thread system
   is initialized, you can do this:
    if (!g_thread_supported ()) g_thread_init (NULL);


 I witness plenty of applications now printing these warnings with the
 new glib2.0 in experimental, and some now crashing.  One quick way to
 workaround or diagnose the problem is to set the following environment
 variable:
    G_SLICE=always-malloc

 This is also useful for valgrinding.


 Please test and fix your packages against glib2.0 2.13.x series which
 sit in experimental.  These are fully compatible with 2.12.x (just not
 API or ABI stable for the new 2.13.x API additions).

   Cheers,

 [1] Memory slices provide a space-efficient and multi-processing
 scalable way to allocate equal-sized pieces of memory, just like the
 original GMemChunks (from GLib <= 2.8), while avoiding their excessive
 memory-waste, scalability and performance problems.
 [2] <http://developer.gnome.org/doc/API/2.2/glib/>
-- 
Loïc Minier



Reply to: