From owner-freebsd-smp@FreeBSD.ORG Wed Sep 17 08:45:46 2003 Return-Path: Delivered-To: freebsd-smp@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 69C8F16A4B3 for ; Wed, 17 Sep 2003 08:45:46 -0700 (PDT) Received: from mail.speakeasy.net (mail7.speakeasy.net [216.254.0.207]) by mx1.FreeBSD.org (Postfix) with ESMTP id AA3E243FBF for ; Wed, 17 Sep 2003 08:45:45 -0700 (PDT) (envelope-from jhb@FreeBSD.org) Received: (qmail 22461 invoked from network); 17 Sep 2003 15:45:43 -0000 Received: from unknown (HELO server.baldwin.cx) ([216.27.160.63]) (envelope-sender )encrypted SMTP for ; 17 Sep 2003 15:45:43 -0000 Received: from laptop.baldwin.cx (gw1.twc.weather.com [216.133.140.1]) by server.baldwin.cx (8.12.9/8.12.9) with ESMTP id h8HFjZ6Y082459; Wed, 17 Sep 2003 11:45:35 -0400 (EDT) (envelope-from jhb@FreeBSD.org) Message-ID: X-Mailer: XFMail 1.5.4 on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 In-Reply-To: <20030917122543.O8168@gamplex.bde.org> Date: Wed, 17 Sep 2003 11:45:37 -0400 (EDT) From: John Baldwin To: Bruce Evans X-Spam-Checker-Version: SpamAssassin 2.55 (1.174.2.19-2003-05-19-exp) cc: smp@freebsd.org Subject: RE: atomicity of unlocked reads X-BeenThere: freebsd-smp@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: FreeBSD SMP implementation group List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Sep 2003 15:45:46 -0000 On 17-Sep-2003 Bruce Evans wrote: > What guarantees, if any, are there that an unlocked read provides a > valid value (either the current value or a previous value)? Obviously > there are no guarantees if the size of the object being read is different > from the natural memory access size. > > I'm mainly interested in atomic reads of pointers in circular buffers. > The read pointer is only written to by one thread and is locked by > lock R. The write pointer is only written to by another thread and > is locked by a different lock W. Each thread needs to read but not > write the other thread's pointer but doesn't care if it sees a stale > value (it will see an up to date value later), but does care if it > sees a garbage value. It would be nice if each thread doesn't have > to use the other thread's lock, especially when one of the threads is > actually a fast interrupt handler so it can't use the other thread's > lock unless it is a spinlock but wants to be a sleep lock. > > Sometimes even a garbage value from reading an object non-atomically > might not matter. E.g., in sigpending() there seems to be no point > in locking the read, since a snapshot that is inconsistent due to not > locking during the read is little different from a snapshot that is > inconsistent due to the object changing after it is read. I think you can assume that the read will be atomic. I don't think FreeBSD would work very well on a machine where aligned pointer reads/writes weren't atomic. -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve!" - http://www.FreeBSD.org/