qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 1/2] iothread: stash thread ID away


From: Stefan Hajnoczi
Subject: Re: [Qemu-devel] [PATCH 1/2] iothread: stash thread ID away
Date: Tue, 25 Feb 2014 17:17:38 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]