Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 8 Oct 2003 16:54:57 +0200
From:      Bernd Walter <ticso@cicely12.cicely.de>
To:        Harti Brandt <brandt@fokus.fraunhofer.de>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: Dynamic reads without locking.
Message-ID:  <20031008145457.GD13791@cicely12.cicely.de>
In-Reply-To: <20031008144935.O63940@beagle.fokus.fraunhofer.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>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20031008145457.GD13791>