From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=52311 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PxgLi-0000ev-Tf for qemu-devel@nongnu.org; Thu, 10 Mar 2011 08:56:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PxgLg-0003xG-24 for qemu-devel@nongnu.org; Thu, 10 Mar 2011 08:56:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36379) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PxgLf-0003x9-Og for qemu-devel@nongnu.org; Thu, 10 Mar 2011 08:56:16 -0500 Message-ID: <4D78D875.2090101@redhat.com> Date: Thu, 10 Mar 2011 14:56:05 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <4D7767C0.6060609@siemens.com> <1299761979-15197-2-git-send-email-corentin.chary@gmail.com> <4D78CCDF.6090906@redhat.com> <4D78D603.5060000@us.ibm.com> In-Reply-To: <4D78D603.5060000@us.ibm.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: [PATCH 2/2] vnc: don't mess up with iohandlers in the vnc thread List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: kvm@vger.kernel.org, Jan Kiszka , qemu-devel , Anthony Liguori , Corentin Chary , Peter Lieven On 03/10/2011 02:45 PM, Anthony Liguori wrote: > On 03/10/2011 07:06 AM, Paolo Bonzini wrote: >> On 03/10/2011 01:59 PM, Corentin Chary wrote: >>> Instead, we now store the data in a temporary buffer, and use a socket >>> pair to notify the main thread that new data is available. >> >> You can use a bottom half for this instead of a special socket. >> Signaling a bottom half is async-signal- and thread-safe. > > Bottom halves are thread safe? > > I don't think so. > > They probably should be but they aren't today. Creating a new bottom half is not thread-safe, but scheduling one is. Assuming that you never use qemu_bh_schedule_idle, qemu_bh_schedule boils down to: if (bh->scheduled) return; bh->scheduled = 1; /* stop the currently executing CPU to execute the BH ASAP */ qemu_notify_event(); You may have a spurious wakeup if two threads race on the same bottom half (including the signaling thread racing with the IO thread), but overall you can safely treat them as thread-safe. Paolo