From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40044) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WRkln-0008Ql-6i for qemu-devel@nongnu.org; Sun, 23 Mar 2014 11:57:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WRkli-0006gi-HB for qemu-devel@nongnu.org; Sun, 23 Mar 2014 11:57:07 -0400 Received: from mail-ee0-x234.google.com ([2a00:1450:4013:c00::234]:42608) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WRkli-0006gS-9P for qemu-devel@nongnu.org; Sun, 23 Mar 2014 11:57:02 -0400 Received: by mail-ee0-f52.google.com with SMTP id e49so3496835eek.25 for ; Sun, 23 Mar 2014 08:57:00 -0700 (PDT) Date: Sun, 23 Mar 2014 16:56:58 +0100 From: Stefan Hajnoczi Message-ID: <20140323155658.GA18228@stefanha-thinkpad.hitronhub.home> References: <1381226311-23489-1-git-send-email-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1381226311-23489-1-git-send-email-stefanha@redhat.com> Subject: Re: [Qemu-devel] [PATCH] osdep: initialize glib threads in all QEMU tools List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: mario.dechenno@unina2.it, Paolo Bonzini , qemu-devel@nongnu.org, Kevin Wolf On Tue, Oct 08, 2013 at 11:58:31AM +0200, Stefan Hajnoczi wrote: > glib versions prior to 2.31.0 require an explicit g_thread_init() call > to enable multi-threading. > > Failure to initialize threading causes glib to take single-threaded code > paths without synchronization. For example, the g_slice allocator will > crash due to race conditions. > > Fix this for all QEMU tool programs (qemu-nbd, qemu-io, qemu-img) by > moving the g_thread_init() call from vl.c:main() into a new > osdep.c:thread_init() constructor function. > > thread_init() has __attribute__((constructor)) and is automatically > invoked by the runtime during startup. > > We can now drop the "simple" trace backend's g_thread_init() call since > thread_init() already called it. > > Note that we must keep coroutine-gthread.c's g_thread_init() call which > is located in a constructor function. There is no guarantee for > constructor function ordering so thread_init() may only be called later. > > Reported-by: Mario de Chenno > Signed-off-by: Stefan Hajnoczi > --- > trace/simple.c | 9 --------- > util/osdep.c | 18 ++++++++++++++++++ > vl.c | 8 -------- > 3 files changed, 18 insertions(+), 17 deletions(-) Applied to my block tree, we need this for QEMU 2.0: https://github.com/stefanha/qemu/commits/block Stefan