From owner-freebsd-hackers@FreeBSD.ORG Wed Oct 8 05:45:56 2003 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2CA3716A4B3; Wed, 8 Oct 2003 05:45:56 -0700 (PDT) Received: from srv1.cosmo-project.de (srv1.cosmo-project.de [213.83.6.106]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8105D43FBF; Wed, 8 Oct 2003 05:45:54 -0700 (PDT) (envelope-from ticso@cicely12.cicely.de) Received: from cicely5.cicely.de (cicely5.cicely.de [IPv6:3ffe:400:8d0:301:200:92ff:fe9b:20e7]) (authenticated bits=0) h98Cjit2074420 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=OK); Wed, 8 Oct 2003 14:45:48 +0200 (CEST) (envelope-from ticso@cicely12.cicely.de) Received: from cicely12.cicely.de (cicely12.cicely.de [IPv6:3ffe:400:8d0:301::12]) by cicely5.cicely.de (8.12.10/8.12.10) with ESMTP id h98CjgS8027142 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 8 Oct 2003 14:45:43 +0200 (CEST) (envelope-from ticso@cicely12.cicely.de) Received: from cicely12.cicely.de (localhost [127.0.0.1]) by cicely12.cicely.de (8.12.10/8.12.10) with ESMTP id h98Cjg2u033321; Wed, 8 Oct 2003 14:45:42 +0200 (CEST) (envelope-from ticso@cicely12.cicely.de) Received: (from ticso@localhost) by cicely12.cicely.de (8.12.10/8.12.10/Submit) id h98Cjgkx033320; Wed, 8 Oct 2003 14:45:42 +0200 (CEST) (envelope-from ticso) Date: Wed, 8 Oct 2003 14:45:42 +0200 From: Bernd Walter To: Harti Brandt Message-ID: <20031008124541.GB13791@cicely12.cicely.de> References: <20031008083059.GA520@garage.freebsd.pl> <20031008114506.I63940@beagle.fokus.fraunhofer.de> <20031008101222.GB520@garage.freebsd.pl> <20031008120134.GA13791@cicely12.cicely.de> <20031008140803.U63940@beagle.fokus.fraunhofer.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20031008140803.U63940@beagle.fokus.fraunhofer.de> X-Operating-System: FreeBSD cicely12.cicely.de 5.1-CURRENT alpha User-Agent: Mutt/1.5.4i cc: hsu@freebsd.org cc: rwatson@freebsd.org cc: ticso@cicely.de cc: freebsd-hackers@freebsd.org Subject: Re: Dynamic reads without locking. X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: ticso@cicely.de List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Oct 2003 12:45:56 -0000 On Wed, Oct 08, 2003 at 02:11:12PM +0200, Harti Brandt wrote: > On Wed, 8 Oct 2003, Bernd Walter wrote: > > BW>On Wed, Oct 08, 2003 at 12:12:22PM +0200, Pawel Jakub Dawidek wrote: > BW>> But I'm not talking about non-atomic reads. What I'm want to show is that > BW>> even atomic read (without lock) is dangerous in some cases. > BW> > BW>The above mtx_lock/read/mt_unlock case doesn't make sense, because it > BW>only garanties an up to date value, but you cache it in a local > BW>variable which again brings it out of date when used outside the lock. > > You might (for what ever reason) not care that the value gets out of date > later on, but care that it is correct and consistent in itself. In this > case, if foo is large (64-bit or a structure) the mtx_lock/read/mtx_unlock > makes perfect sense because it guarantees that the value is not changed > while you're copying it (non-atomically). We agree here, but the topic was for atomic reads. If you read a 64 bit value you have to be shure that 64 bit values can be read atomicaly and if they are also written atomicaly then there is no reason to worry about the cosistency of the value itself. I'm not shure if 64 bit values are atomic on all platforms, but they are on some - at least on alpha. On all our platforms reading and writing 8, 16 and 32 bit values should be atomic if they are naturaly aligned - correct me if I'm wrong. Well if you write a 32 bit value with byte acces (e.g. with byte order macros), then you are lost even with a atomic 32 bit read. -- B.Walter BWCT http://www.bwct.de ticso@bwct.de info@bwct.de