Date: Wed, 8 Oct 2003 12:12:22 +0200 From: Pawel Jakub Dawidek <nick@garage.freebsd.pl> To: Harti Brandt <brandt@fokus.fraunhofer.de> Cc: rwatson@freebsd.org Subject: Re: Dynamic reads without locking. Message-ID: <20031008101222.GB520@garage.freebsd.pl> In-Reply-To: <20031008114506.I63940@beagle.fokus.fraunhofer.de> References: <20031008083059.GA520@garage.freebsd.pl> <20031008114506.I63940@beagle.fokus.fraunhofer.de>
next in thread | previous in thread | raw e-mail | index | archive | help
--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+--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20031008101222.GB520>