From owner-freebsd-hackers@FreeBSD.ORG Wed Oct 8 03:09:55 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 9F63C16A4B3; Wed, 8 Oct 2003 03:09:55 -0700 (PDT) Received: from milla.ask33.net (milla.ask33.net [217.197.166.60]) by mx1.FreeBSD.org (Postfix) with ESMTP id A254343FE0; Wed, 8 Oct 2003 03:09:54 -0700 (PDT) (envelope-from nick@milla.ask33.net) Received: by milla.ask33.net (Postfix, from userid 1001) id E5F0B3ABB35; Wed, 8 Oct 2003 12:12:22 +0200 (CEST) Date: Wed, 8 Oct 2003 12:12:22 +0200 From: Pawel Jakub Dawidek To: Harti Brandt Message-ID: <20031008101222.GB520@garage.freebsd.pl> References: <20031008083059.GA520@garage.freebsd.pl> <20031008114506.I63940@beagle.fokus.fraunhofer.de> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-md5; protocol="application/pgp-signature"; boundary="KqIDP7BYbqnwKRO+" Content-Disposition: inline In-Reply-To: <20031008114506.I63940@beagle.fokus.fraunhofer.de> X-PGP-Key-URL: http://garage.freebsd.pl/jules.asc X-OS: FreeBSD 4.8-RELEASE-p9 i386 X-URL: http://garage.freebsd.pl User-Agent: Mutt/1.5.1i cc: freebsd-hackers@freebsd.org cc: hsu@freebsd.org cc: rwatson@freebsd.org Subject: Re: Dynamic reads without locking. X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list 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 10:09:55 -0000 --KqIDP7BYbqnwKRO+ Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Oct 08, 2003 at 11:51:06AM +0200, Harti Brandt wrote: +> You need to lock when reading if you insist on consistent data. Even a +> simple read may be non-atomic (this should be the case for 64bit +> operations on all our platforms). So you need to do +>=20 +> mtx_lock(&foo_mtx); +> bar =3D foo; +> mtx_unlock(&foo_mtx); +>=20 +> if foo is a datatype that is not guaranteed to be red atomically. For +> 8-bit data you should be safe without the lock on any architecture. I'm +> not sure for 16 and 32 bit, but for 64-bit you need the look for all +> our architectures, I think. But I'm not talking about non-atomic reads. What I'm want to show is that even atomic read (without lock) is dangerous in some cases. +> If you don't care about occasionally reading false data (for statistics = or +> such stuff) you can go without the lock. I'm afraid that many developers thinks that atomic reads are always safe without locks (there are many such reads in sources). I hope I'm wrong. --=20 Pawel Jakub Dawidek pawel@dawidek.net UNIX Systems Programmer/Administrator http://garage.freebsd.pl Am I Evil? Yes, I Am! http://cerber.sourceforge.net --KqIDP7BYbqnwKRO+ Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (FreeBSD) iQCVAwUBP4PjBj/PhmMH/Mf1AQGS/wQAhEFJbDlDKRSAgG1SCE6eC01e2x7DyovZ rRJhXdNwwf4ZvEfKgQXuSq7C9hALh/xvGr5nJOB5d+8/b7Nc99oLCzvNIEqYW89g nQ+IkD0Xywc9IpiKUAkKeWeUqznGM9JV/b8ZAqXUi/jnjvdma+ruJ/LUTJW+rEft SJgvseL2QIs= =qQV1 -----END PGP SIGNATURE----- --KqIDP7BYbqnwKRO+--