From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53487) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WILtJ-0005OK-Ka for qemu-devel@nongnu.org; Tue, 25 Feb 2014 12:34:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WILtD-0008Qg-Jd for qemu-devel@nongnu.org; Tue, 25 Feb 2014 12:34:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:16677) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WILtD-0008QR-Ba for qemu-devel@nongnu.org; Tue, 25 Feb 2014 12:33:55 -0500 Message-ID: <530CD3FD.4030609@redhat.com> Date: Tue, 25 Feb 2014 10:33:49 -0700 From: Eric Blake MIME-Version: 1.0 References: <1393348774-14663-1-git-send-email-stefanha@redhat.com> <1393348774-14663-2-git-send-email-stefanha@redhat.com> In-Reply-To: <1393348774-14663-2-git-send-email-stefanha@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="kCOEqiejpELaFvcXvlUpJTRMP7aluwd6O" Subject: Re: [Qemu-devel] [PATCH v2 1/2] iothread: stash thread ID away List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi , qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , "Shergill, Gurinder" , "Vinod, Chegu" , Luiz Capitulino This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --kCOEqiejpELaFvcXvlUpJTRMP7aluwd6O Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 02/25/2014 10:19 AM, Stefan Hajnoczi wrote: > Keep the thread ID around so we can report it via QMP. >=20 > There's only one problem: qemu_get_thread_id() (gettid() wrapper on > Linux) must be called from the thread itself. There is no way to get > the thread ID outside the thread. >=20 > This patch uses a condvar to wait for iothread_run() to populate the > thread_id inside the thread. >=20 > + > + /* Wait for initialization to complete */ > + qemu_mutex_lock(&iothread->init_done_lock); > + qemu_cond_wait(&iothread->init_done_cond, > + &iothread->init_done_lock); > + qemu_mutex_unlock(&iothread->init_done_lock); Generally, cond_wait needs to be done in a loop, where you also check the condition (in this case, that thread_id was actually set) - a pthread implementation is allowed to do spurious wakeups even if no other thread has managed to change the condition that you were waiting fo= r. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --kCOEqiejpELaFvcXvlUpJTRMP7aluwd6O Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJTDNP9AAoJEKeha0olJ0Nqa8UH/23KlD1dplgs2pPGqN2I7mDF bUj/wHvhYhX06QE8zjcNojc7ble98ON7iY+jKi4lihYqrGg8SrfFKlNSpmvHlpDS cyl5GkSCclFOX/KKSt7acWjixRj5yyr4LGzveTCMQjHR7Yh10t4/Zz6VuBtDCW5L 3alO3g1tk84QvZpA0tmovsKuDS10CCoujJhFvy5raD0yxe+33lLWDAZChgQaPDkc ih0LUyWboiIHviAQ2/Fmfec2U0uNbIrzkVZlBeZQutzcFrhKaijwe9heS0NWxXRo +5xiTAOLLsvgQfwc/Bod2ywYhpxMea9HnOUC8cf00+C4WWVK6jLWRp0D5bGR/6E= =9eau -----END PGP SIGNATURE----- --kCOEqiejpELaFvcXvlUpJTRMP7aluwd6O--