qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 2/4] chardev: make qemu_chr_fe_set_handlers() context switching safer
Date: Fri, 22 Feb 2019 16:56:33 +0800	[thread overview]
Message-ID: <20190222085633.GL8904@xz-x1> (raw)
In-Reply-To: <20190221080357.GC3091@xz-x1>

On Thu, Feb 21, 2019 at 04:03:57PM +0800, Peter Xu wrote:

[...]

> > +static gboolean
> > +main_context_wait_cb(gpointer user_data)
> > +{
> > +    struct MainContextWait *w = user_data;
> > +
> > +    qemu_mutex_lock(&w->lock);
> > +    qemu_cond_signal(&w->cond);
> > +    /* wait until switching is over */
> > +    qemu_cond_wait(&w->cond, &w->lock);
> 
> Could previous signal() directly wake up itself here?  Man
> pthread_cond_broadcast says:
> 
>        The pthread_cond_signal() function shall unblock at least one
>        of the threads that are blocked on the specified condition
>        variable cond (if any threads are blocked on cond).
> 
>        If more than one thread is blocked on a condition variable, the
>        scheduling policy shall determine the order in which threads
>        are unblocked.
> 
> So AFAIU it could, because neither there's a restriction on ordering
> of how waiters are waked up, nor there's a limitation on how many
> waiters will be waked up by a single signal().
> 
> Why not simply use two semaphores?  Then locks can be avoided too.

Please feel free to skip this question.  I think when cond_signal()
right before cond_wait() this thread is not yet in the waiting list so
at least my question seems invalid.  Then cond+lock looks fine
comparing to sems.  Sorry for the noise.

Regards,

-- 
Peter Xu

  parent reply	other threads:[~2019-02-22  8:57 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-20 16:06 [Qemu-devel] [PATCH 0/4] RFC: make chardev context switching safer Marc-André Lureau
2019-02-20 16:06 ` [Qemu-devel] [PATCH 1/4] iothread: wait until the glib context is acquired Marc-André Lureau
2019-02-21  7:59   ` Peter Xu
2019-02-21 10:39     ` Marc-André Lureau
2019-02-22  3:29       ` Peter Xu
2019-02-20 16:06 ` [Qemu-devel] [PATCH 2/4] chardev: make qemu_chr_fe_set_handlers() context switching safer Marc-André Lureau
2019-02-21  8:03   ` Peter Xu
2019-02-22  8:32     ` Philippe Mathieu-Daudé
2019-02-22  8:58       ` Marc-André Lureau
2019-02-22  8:56     ` Peter Xu [this message]
2019-02-20 16:06 ` [Qemu-devel] [PATCH 3/4] monitor: set the chardev context from the main context/thread Marc-André Lureau
2019-02-20 16:06 ` [Qemu-devel] [PATCH 4/4] char-socket: restart the reconnect timer to switch context Marc-André Lureau
2019-02-21  7:57 ` [Qemu-devel] [PATCH 0/4] RFC: make chardev context switching safer Peter Xu
2019-02-21 10:48   ` Marc-André Lureau

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=20190222085633.GL8904@xz-x1 \
    --to=peterx@redhat.com \
    --cc=armbru@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).