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

2014-02-25 Thread Paolo Bonzini
Il 25/02/2014 17:17, Stefan Hajnoczi ha scritto: 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. It also depends on the low-level lock implementation. I looked at the C one and it's not safe, the x86-o

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

2014-02-25 Thread Stefan Hajnoczi
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 i

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

2014-02-25 Thread Paolo Bonzini
Il 25/02/2014 16:42, Stefan Hajnoczi ha scritto: I guess you're saying that while unlocking the mutex is atomic, that doesn't guarantee pthread won't access the mutex internal state some more after it has unlocked it. Therefore it's not safe for another thread to destroy the mutex even after it

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

2014-02-25 Thread Stefan Hajnoczi
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 i

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

2014-02-24 Thread Paolo Bonzini
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 c

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

2014-02-24 Thread Stefan Hajnoczi
On Fri, Feb 21, 2014 at 04:18:30PM +0100, Paolo Bonzini wrote: > Il 21/02/2014 15:51, Stefan Hajnoczi ha scritto: > >Keep the thread ID around so we can report it via QMP. > > > >There's only one problem: qemu_get_thread_id() (gettid() wrapper on > >Linux) must be called from the thread itself. Th

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

2014-02-21 Thread Paolo Bonzini
Il 21/02/2014 15:51, Stefan Hajnoczi ha scritto: Keep the thread ID around so we can report it via QMP. 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. This patch uses a c

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

2014-02-21 Thread Stefan Hajnoczi
Keep the thread ID around so we can report it via QMP. 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. This patch uses a condvar to wait for iothread_run() to populate the t