From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39019) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WHyiL-0000W3-UU for qemu-devel@nongnu.org; Mon, 24 Feb 2014 11:49:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WHyiF-0007LA-U8 for qemu-devel@nongnu.org; Mon, 24 Feb 2014 11:49:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52148) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WHyiF-0007L6-Hs for qemu-devel@nongnu.org; Mon, 24 Feb 2014 11:49:03 -0500 Message-ID: <530B77CD.9020502@redhat.com> Date: Mon, 24 Feb 2014 17:48:13 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <1392994280-9675-1-git-send-email-stefanha@redhat.com> <1392994280-9675-2-git-send-email-stefanha@redhat.com> <53076E46.3020109@redhat.com> <20140224155359.GH23185@stefanha-thinkpad.hitronhub.home> In-Reply-To: <20140224155359.GH23185@stefanha-thinkpad.hitronhub.home> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/2] iothread: stash thread ID away List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: "Shergill, Gurinder" , "Vinod, Chegu" , qemu-devel@nongnu.org, Stefan Hajnoczi , Luiz Capitulino Il 24/02/2014 16:53, Stefan Hajnoczi ha scritto: >>> > >+ qemu_cond_destroy(&init_info.init_done_cond); >>> > >+ qemu_mutex_destroy(&init_info.init_done_lock); >> > >> > Destroying the mutex here is racy. You need to keep it until the >> > iothread is destroyed. > I don't think so: > > qemu_cond_signal() is called with the mutex held. Therefore, our > qemu_cond_wait() followed by qemu_mutex_unlock() will only complete once > the thread has released the mutex. > > The thread will never touch the mutex again so it is safe to destroy it. > There is no race condition. Could qemu_mutex_destroy run while the other thread has already released the main thread, but before it returns? As far as I know, the only time when it is safe to destroy the "last" synchronization object (in this case the mutex is the last, the condvar is not) is after pthread_join. Paolo