On 06/03/2015 08:03, Halsey Pian wrote: > I have two threads to write two seperate qcow2 files, but after a > while, the writing would be aborted in qemu_coroutine_enter, and report > error “"Co-routine re-entered recursively” . > > Qemu should be thread safe, right? It seems that there are some > variables is not thread safe? Could you have a chance to look it? Thanks!
QEMU is thread safe but you need to add explicit locking or use separate event loops in each thread. If you want to write from separate thread, you need to do one of the following: 1) use one AioContext per file, and add an AioContext-based event loop to each thread (see backends/iothread.c); 2) use one AioContext per file, add it (as a GSource) to a GMainContext and use a GMainLoop-based event loop to each thread; 3) use aio_context_acquire and aio_context_release around each blk_* or bdrv_* call. Paolo