On Tue, Aug 21, 2018 at 08:13:59PM +0200, Marc-André Lureau wrote:
> Hi
> 
> On Wed, Aug 15, 2018 at 3:37 PM, Peter Xu <pet...@redhat.com> wrote:
> > When we reach monitor_qmp_setup_handlers_bh() we must be using the
> > IOThread then, so no need to check against it any more.  Instead, we
> > assert.
> >
> > Reviewed-by: Markus Armbruster <arm...@redhat.com>
> > Signed-off-by: Peter Xu <pet...@redhat.com>
> 
> That's a clear simplification that I also found, so ack in principle.
> 
> However, I don't understand the need of a BH in the first place.
> monitor_get_io_context() will return the iothread associated context.
> Could you explain?
> thanks

Please refer to the comment in monitor_init():

        /*
        * We can't call qemu_chr_fe_set_handlers() directly here
        * since chardev might be running in the monitor I/O
        * thread.  Schedule a bottom half.
        */
        aio_bh_schedule_oneshot(monitor_get_aio_context(),
                                monitor_qmp_setup_handlers_bh, mon);

To be more specific: in qemu_chr_fe_set_handlers() after we call
qemu_chr_be_update_read_handlers() then the iothread might already
have started to operate on the chardev, so it can race with
qemu_chr_fe_set_handlers() itself if we call it directly in the main
thread.

Regards,

-- 
Peter Xu

Reply via email to