atomicity of unlocked reads

Bruce Evans bde at zeta.org.au
Tue Sep 16 23:26:51 PDT 2003


On Tue, 16 Sep 2003, Frank Mayhar wrote:

> Bruce Evans wrote:
> > What guarantees, if any, are there that an unlocked read provides a
> > valid value (either the current value or a previous value)?  Obviously
> > there are no guarantees if the size of the object being read is different
> > from the natural memory access size.
>
> I think that this may depend on the architecture of the target, but as I
> understand it, in general an entity that is read in one (bus) operation
> is guaranteed to be valid.  These days that entity is generally 32 or 64
> bits.  The key is that the bus is locked during the entire read or write
> cycle so that reads and writes are serialized by the hardware.
>
> So the answer is that yes, there are guarantees, but you still have to
> be careful and aware of the semantics of the target hardware.

I'll give up micro-optimizing this and use an atomic instruction since
I want it to work in MI code without ifdefs for the target hardware.
atomic_load_ptr() could hide the details, but we currently only have
atomic_load_acq_ptr() which gives more than I need.

Bruce


More information about the freebsd-smp mailing list