All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>, qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	"Shergill, Gurinder" <gurinder.shergill@hp.com>,
	"Vinod, Chegu" <chegu_vinod@hp.com>,
	Luiz Capitulino <lcapitulino@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2 1/2] iothread: stash thread ID away
Date: Tue, 25 Feb 2014 10:33:49 -0700	[thread overview]
Message-ID: <530CD3FD.4030609@redhat.com> (raw)
In-Reply-To: <1393348774-14663-2-git-send-email-stefanha@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1064 bytes --]

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 #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

  reply	other threads:[~2014-02-25 17:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-25 17:19 [Qemu-devel] [PATCH v2 0/2] dataplane: add query-iothreads QMP command Stefan Hajnoczi
2014-02-25 17:19 ` [Qemu-devel] [PATCH v2 1/2] iothread: stash thread ID away Stefan Hajnoczi
2014-02-25 17:33   ` Eric Blake [this message]
2014-02-27 10:24     ` Stefan Hajnoczi
2014-02-25 17:19 ` [Qemu-devel] [PATCH v2 2/2] qmp: add query-iothreads command Stefan Hajnoczi
2014-02-25 17:36   ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=530CD3FD.4030609@redhat.com \
    --to=eblake@redhat.com \
    --cc=chegu_vinod@hp.com \
    --cc=gurinder.shergill@hp.com \
    --cc=kwolf@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.