From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:54707) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T8tUG-0007J3-Ku for qemu-devel@nongnu.org; Tue, 04 Sep 2012 09:48:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T8tUA-0005rK-J4 for qemu-devel@nongnu.org; Tue, 04 Sep 2012 09:48:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57760) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T8tUA-0005r0-Aq for qemu-devel@nongnu.org; Tue, 04 Sep 2012 09:48:10 -0400 Message-ID: <5046068B.3000702@redhat.com> Date: Tue, 04 Sep 2012 15:47:55 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1346663926-20188-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1346663926-20188-2-git-send-email-xiawenc@linux.vnet.ibm.com> <5044B720.5080205@redhat.com> <5045A2BB.3060007@linux.vnet.ibm.com> <5045E78D.1080100@redhat.com> In-Reply-To: <5045E78D.1080100@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/6] libqblock APIs List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: kwolf@redhat.com, stefanha@gmail.com, aliguori@us.ibm.com, Wenchao Xia , qemu-devel@nongnu.org Il 04/09/2012 13:35, Eric Blake ha scritto: >> > No, it should be only called once, any other thread should not call >> > it again, will document it. About the multiple thread user case, qemu >> > block layer can't support that now, will fix that later. > What a shame. That makes libraries much harder to use. It is much > nicer to design a library where the initialization is idempotent and > thread-safe, to be called from multiple threads. Consider: > > app links against liba and libb; > liba links against libqb > libb links against libqb > > How am I supposed to write liba and libb to guarantee only one single > race-free call to libqblock_init, unless libqblock_init() is idempotent? I agree, libqblock_init should use pthread_once (or we can add QemuOnce to qemu-thread-*.c). Paolo