From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42404) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTooO-0004na-Ej for qemu-devel@nongnu.org; Fri, 06 Mar 2015 04:44:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YTooK-0001gZ-DU for qemu-devel@nongnu.org; Fri, 06 Mar 2015 04:44:52 -0500 Received: from mail-wg0-x22e.google.com ([2a00:1450:400c:c00::22e]:41774) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTooK-0001gC-6E for qemu-devel@nongnu.org; Fri, 06 Mar 2015 04:44:48 -0500 Received: by wghl2 with SMTP id l2so15093608wgh.8 for ; Fri, 06 Mar 2015 01:44:46 -0800 (PST) Sender: Paolo Bonzini Message-ID: <54F9770A.6030205@redhat.com> Date: Fri, 06 Mar 2015 10:44:42 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <009a01d057db$baf86640$30e932c0$@gmail.com> In-Reply-To: <009a01d057db$baf86640$30e932c0$@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [Bug] qemu_coroutine_enter abort and report error "Co-routine re-entered recursively" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Halsey Pian , qemu-devel@nongnu.org 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