From owner-freebsd-hackers@FreeBSD.ORG Wed Oct 8 07:55:18 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 80C5616A4BF; Wed, 8 Oct 2003 07:55:18 -0700 (PDT) Received: from srv1.cosmo-project.de (srv1.cosmo-project.de [213.83.6.106]) by mx1.FreeBSD.org (Postfix) with ESMTP id C40BD43FE1; Wed, 8 Oct 2003 07:55:13 -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) h98Et4t2076022 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=OK); Wed, 8 Oct 2003 16:55:07 +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 h98Et1S8027818 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 8 Oct 2003 16:55:02 +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 h98Et12u033756; Wed, 8 Oct 2003 16:55:01 +0200 (CEST) (envelope-from ticso@cicely12.cicely.de) Received: (from ticso@localhost) by cicely12.cicely.de (8.12.10/8.12.10/Submit) id h98EswQD033751; Wed, 8 Oct 2003 16:54:58 +0200 (CEST) (envelope-from ticso) Date: Wed, 8 Oct 2003 16:54:57 +0200 From: Bernd Walter To: Harti Brandt Message-ID: <20031008145457.GD13791@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> <20031008124541.GB13791@cicely12.cicely.de> <20031008144935.O63940@beagle.fokus.fraunhofer.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20031008144935.O63940@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 14:55:18 -0000 On Wed, Oct 08, 2003 at 02:58:02PM +0200, Harti Brandt wrote: > uint8_t foo; > > (guaranteeing that the data type itself is atomic). But if a writer sets > foo as above and you read foo without locking, you might get a wrong > value: > > mtx_lock(...) > foo = 77; > > -> bar = foo; /* bar is 77 */ > > foo &= 0x1f; > mtx_unlock(...) That part is obviuosly. > Even if you write > > foo = data & 0x1f > > it may not help (one has to understand all that stuff about sequence > points in the C-standard). Unlikely, but I agree that it might cause problems. Maybe we should have atomic_load/atomic_store without barriers to be 100% shure on that. > So you can go without locking in the reader only if: > > - the datatype is atomic (depends on your architecture) > - all writers ensure that they write only consistent values to the > variable > > The 2nd point needs very careful thinking in every case. Agreed. -- B.Walter BWCT http://www.bwct.de ticso@bwct.de info@bwct.de