From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32796) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WIKhc-0006a8-ST for qemu-devel@nongnu.org; Tue, 25 Feb 2014 11:17:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WIKhW-0006wG-Sy for qemu-devel@nongnu.org; Tue, 25 Feb 2014 11:17:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:26847) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WIKhW-0006wC-Kq for qemu-devel@nongnu.org; Tue, 25 Feb 2014 11:17:46 -0500 Date: Tue, 25 Feb 2014 17:17:38 +0100 From: Stefan Hajnoczi Message-ID: <20140225161738.GD2374@stefanha-thinkpad.redhat.com> 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> <530B77CD.9020502@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <530B77CD.9020502@redhat.com> 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: Paolo Bonzini Cc: Stefan Hajnoczi , "Shergill, Gurinder" , "Vinod, Chegu" , qemu-devel@nongnu.org, Luiz Capitulino On Mon, Feb 24, 2014 at 05:48:13PM +0100, Paolo Bonzini wrote: > 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. For the default mutex type (PTHREAD_MUTEX_TIMED_NP) glibc looks safe to me. The other mutex types are trickier and I haven't audited them. Anyway, I can just move the mutex into the IOThread object and destroy it after the thread is joined :). Stefan