From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45050) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YDyKX-0000LX-Ha for qemu-devel@nongnu.org; Wed, 21 Jan 2015 11:40:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YDyKS-0003Y4-Ko for qemu-devel@nongnu.org; Wed, 21 Jan 2015 11:40:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47484) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YDyKS-0003Xy-9Z for qemu-devel@nongnu.org; Wed, 21 Jan 2015 11:40:28 -0500 Message-ID: <54BFD677.2070905@redhat.com> Date: Wed, 21 Jan 2015 17:40:23 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <1421857693-12014-1-git-send-email-jslaby@suse.cz> In-Reply-To: <1421857693-12014-1-git-send-email-jslaby@suse.cz> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v4 1/1] pci-host: add educational driver List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jiri Slaby , qemu-devel@nongnu.org On 21/01/2015 17:28, Jiri Slaby wrote: > + if (atomic_fetch_or(&edu->status, EDU_STATUS_COMPUTING) & EDU_STATUS_COMPUTING) { Theoretically the other thread could see EDU_STATUS_COMPUTING here and not enter the condvar wait. So... > + break; > + } > + qemu_mutex_lock(&edu->thr_mutex); > + edu->fact = val; > + qemu_cond_signal(&edu->thr_cond); > + qemu_mutex_unlock(&edu->thr_mutex); ... just one change: if (atomic_read(&edu->status) & EDU_STATUS_COMPUTING) { break; } /* EDU_STATUS_COMPUTING cannot go 0->1 concurrently, because * it is only set in this function and it is under the iothread * mutex. */ qemu_mutex_lock(&edu->thr_mutex); edu->fact = val; atomic_or(&edu->status), EDU_STATUS_COMPUTING); qemu_cond_signal(&edu->thr_cond); qemu_mutex_unlock(&edu->thr_mutex); If you are okay with this change, I'll apply the patch to my tree. Paolo