On 16/01/2017 13:58, Daniel P. Berrange wrote: >> + * Request that qio_channel_yield() sets I/O handlers on >> + * the given #AioContext. If @ctx is %NULL, qio_channel_yield() >> + * uses QEMU's main thread event loop. >> + */ > Can you note that it is explicitly permitted to call this while > inside a qio_channel_yield().
Yes: * You can move a #QIOChannel from an #AioContext to another even if * I/O handlers are set for a coroutine. However, #QIOChannel provides * no synchronization between the calls to qio_channel_yield() and * qio_channel_set_aio_context(). * * Therefore you should first call qio_channel_detach_aio_context() * to ensure that the coroutine is not entered concurrently. Then, * while the coroutine has yielded, call qio_channel_set_aio_context(), * and then aio_co_schedule() to place the coroutine on the new * #AioContext. The calls to qio_channel_detach_aio_context() * and qio_channel_set_aio_context() should be protected with * aio_context_acquire() and aio_context_release(). Paolo