From nobody Sun Nov 9 14:49:24 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550680641152881.602795757942; Wed, 20 Feb 2019 08:37:21 -0800 (PST) Received: from localhost ([127.0.0.1]:42432 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwUs0-0003oC-47 for importer@patchew.org; Wed, 20 Feb 2019 11:37:16 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41411) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwUOY-0002Vc-QU for qemu-devel@nongnu.org; Wed, 20 Feb 2019 11:06:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwUOL-0005JF-Mk for qemu-devel@nongnu.org; Wed, 20 Feb 2019 11:06:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60004) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gwUOL-0005FY-C2 for qemu-devel@nongnu.org; Wed, 20 Feb 2019 11:06:37 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EC8D113B24A for ; Wed, 20 Feb 2019 16:06:34 +0000 (UTC) Received: from localhost (ovpn-112-64.ams2.redhat.com [10.36.112.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 664496108F; Wed, 20 Feb 2019 16:06:32 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2019 17:06:25 +0100 Message-Id: <20190220160628.6555-2-marcandre.lureau@redhat.com> In-Reply-To: <20190220160628.6555-1-marcandre.lureau@redhat.com> References: <20190220160628.6555-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 20 Feb 2019 16:06:35 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/4] iothread: wait until the glib context is acquired X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Another thread may acquire the glib context (temporarily) before g_main_context_push_thread_default(). This can happen with the following qemu_chr_fe_set_handlers() modifications. Unfortunately, g_main_context_wait() is deprecated in glib 2.58 (apparently it was a broken interface). Use a polling loop. Signed-off-by: Marc-Andr=C3=A9 Lureau --- iothread.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/iothread.c b/iothread.c index e615b7ae52..93cc3aa875 100644 --- a/iothread.c +++ b/iothread.c @@ -70,6 +70,11 @@ static void *iothread_run(void *opaque) if (iothread->running && atomic_read(&iothread->worker_context)) { GMainLoop *loop; =20 + /* we may race with another thread acquiring the context */ + while (!g_main_context_acquire(iothread->worker_context)) { + g_usleep(10000); + } + g_main_context_push_thread_default(iothread->worker_context); iothread->main_loop =3D g_main_loop_new(iothread->worker_context, TRUE); @@ -80,6 +85,8 @@ static void *iothread_run(void *opaque) g_main_loop_unref(loop); =20 g_main_context_pop_thread_default(iothread->worker_context); + + g_main_context_release(iothread->worker_context); } } =20 --=20 2.21.0.rc1