GNOME Bugzilla – Bug 595757
gio does not handle "late" g_thread_init()
Last modified: 2010-02-17 22:03:58 UTC
While libglib goes to great lengths to retcon its threadsafety if g_thread_init() is called while the program is already running, libgio does not. This means, at the moment: - If you call g_cancellable_get_type() and then later initialize threads, then later calls to certain GCancellable methods will crash because cancellable_cond is NULL. - If you call g_resolver_get_default() and then later initialize threads, then later calls to resolver methods will potentially crash/block/fail randomly. Fixing these is slightly more awkward than in the glib cases, since gio has no equivalent of g_thread_init_glib(). One way would be to add something like "g_thread_add_init_callback()" that you can use to add more methods to the list that gets called from g_thread_init_glib(). Failing that, GCancellable already has a static mutex it could use to protect the fixup, and we could do various tricks with atomic pointers and static mutexes and stuff in the resolver code too. Or we could just say "ha ha, we told you you had to call g_thread_init first".
Since GIO doesn't work without calling g_type_init(), and g_type_init() calls g_thread_init(NULL) now as of http://git.gnome.org/browse/glib/commit/?id=fa2bced1f30f93443ef43ce8b5b1e437cd07168c, isn't this effectively fixed?
yup