Commit fa2bced1 authored by Alexander Larsson's avatar Alexander Larsson

Enable threads in g_type_init()

This means threads will be supported for all gobject libraries/applications
and initialized early enough to not cause any problems.

This solves the problem of libraries needing threadsafety. Previosly
they just called g_threads_init() anyway, which often works but sometimes
breaks in unexpected ways.

See this thread for more details:
parent 0df3ca8f
......@@ -48,6 +48,14 @@ However, many libraries above glib does not support late initialization of
threads, so doing this should be avoided if possible.
Please note that since version 2.24 the GObject initialization
function g_type_init() initializes threads (with a %NULL argument), so
most applications, including those using Gtk+ will run with threads
enabled. If you want a special thread implementation, make sure you
call g_thread_init() before g_type_init() is called.
After calling g_thread_init(), GLib is completely
thread safe (all global data is automatically locked), but individual
Name: GObject Uninstalled
Description: Object/type system for GLib, Not Installed
Requires: glib-2.0-uninstalled
Requires: glib-2.0-uninstalled,gthread-2.0-uninstalled
Version: @VERSION@
Libs: ${pc_top_builddir}/${pcfiledir}/gobject/
## cflags contains builddir in addition to srcdir because of gmarshal.h
......@@ -5,7 +5,7 @@ includedir=@includedir@
Name: GObject
Description: GLib Type, Object, Parameter and Signal Library
Requires: glib-2.0
Requires: glib-2.0,gthread-2.0
Version: @VERSION@
Libs: -L${libdir} -lgobject-2.0
......@@ -31,7 +31,7 @@ TESTS =
libglib = $(top_builddir)/glib/
libglib = $(top_builddir)/glib/ $(top_builddir)/gthread/
# libraries to compile and install
......@@ -4180,7 +4180,12 @@ g_type_init_with_debug_flags (GTypeDebugFlags debug_flags)
GTypeInfo info;
TypeNode *node;
volatile GType votype;
if (!g_thread_get_initialized())
g_thread_init (NULL);
G_LOCK (type_init_lock);
G_WRITE_LOCK (&type_rw_lock);
......@@ -4284,6 +4289,8 @@ g_type_init_with_debug_flags (GTypeDebugFlags debug_flags)
* to initialize the type system and assorted other code portions
* (such as the various fundamental type implementations or the signal
* system).
* Since version 2.24 this also initializes the thread system
g_type_init (void)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment