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 <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 1/4] iothread: wait until the glib context is acquired
Date: Fri, 22 Feb 2019 11:29:06 +0800	[thread overview]
Message-ID: <20190222032906.GA8904@xz-x1> (raw)
In-Reply-To: <CAMxuvawaLapw0EtqASj6U2C-0oruf06RhqoU4GBjAk2vSZFoZw@mail.gmail.com>

On Thu, Feb 21, 2019 at 11:39:32AM +0100, Marc-André Lureau wrote:
> Hi
> 
> On Thu, Feb 21, 2019 at 9:00 AM Peter Xu <peterx@redhat.com> wrote:
> >
> > On Wed, Feb 20, 2019 at 05:06:25PM +0100, Marc-André Lureau wrote:
> > > Another thread may acquire the glib context (temporarily) before
> > > g_main_context_push_thread_default().
> > >
> > > This can happen with the following qemu_chr_fe_set_handlers()
> > > modifications.
> > >
> > > Unfortunately, g_main_context_wait() is deprecated in glib
> > > 2.58 (apparently it was a broken interface). Use a polling loop.
> > >
> > > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > > ---
> > >  iothread.c | 7 +++++++
> > >  1 file changed, 7 insertions(+)
> > >
> > > diff --git a/iothread.c b/iothread.c
> > > index e615b7ae52..93cc3aa875 100644
> > > --- a/iothread.c
> > > +++ b/iothread.c
> > > @@ -70,6 +70,11 @@ static void *iothread_run(void *opaque)
> > >          if (iothread->running && atomic_read(&iothread->worker_context)) {
> > >              GMainLoop *loop;
> > >
> > > +            /* we may race with another thread acquiring the context */
> > > +            while (!g_main_context_acquire(iothread->worker_context)) {
> > > +                g_usleep(10000);
> > > +            }
> >
> > Could you help explain why need this explicitly?  Since AFAIU
> > g_main_loop_run() below will do context acquire too so IIUC you're
> > taking it twice (while g_main_context_acquire should allow it to
> > happen, though)?
> >
> 
> We call g_main_context_push_thread_default() before run(). It will
> fail if the context is not acquirable.

Thanks for explaining.  It wasn't obvious to me.

I've posted another series to refactor iothread a bit and it should be
able to drop this patch if based on that series (that series should
even remove code instead of adding new).  Please feel free to have a
look, or give it a shot:

  [PATCH 0/4] iothread: create gcontext unconditionally

Regards,

-- 
Peter Xu

  reply	other threads:[~2019-02-22  3:30 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 [this message]
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
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=20190222032906.GA8904@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).