qemu-devel
[Top][All Lists]
Advanced

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

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


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH v2 1/2] iothread: stash thread ID away
Date: Tue, 25 Feb 2014 10:33:49 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0

On 02/25/2014 10:19 AM, Stefan Hajnoczi wrote:
> 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
> thread_id inside the thread.
> 

> +
> +    /* Wait for initialization to complete */
> +    qemu_mutex_lock(&iothread->init_done_lock);
> +    qemu_cond_wait(&iothread->init_done_cond,
> +                   &iothread->init_done_lock);
> +    qemu_mutex_unlock(&iothread->init_done_lock);

Generally, cond_wait needs to be done in a loop, where you also check
the condition (in this case, that thread_id was actually set) - a
pthread implementation is allowed to do spurious wakeups even if no
other thread has managed to change the condition that you were waiting for.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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