Re: [PATCH v5 05/10] rust: sync: atomic: Add atomic {cmp,}xchg operations

Alan Stern
2025-06-30T14:51:04Z

On Mon, Jun 30, 2025 at 12:16:27PM +0200, Andreas Hindborg wrote:
> "Boqun Feng" <boqun.feng@gmail.com> writes:
> > in atomic/ordering.rs, I think I can extend it to:
> >
> > //! - [`Acquire`] provides ordering between the load part of the annotated operation and all the
> > //! following memory accesses, and if there is a store part, it has Relaxed ordering.
> > //! - [`Release`] provides ordering between all the preceding memory accesses and the store part of
> > //! the annotated operation, and if there is load part, it has Relaxed ordering
> >
> > This aligns with what we usually describe things in tool/memory-model/.
>
> Cool. When you start to go into details of ordering concepts, I feel
> like something is missing though. For example for this sentence:
>
> [`Release`] provides ordering between all the preceding memory
> accesses and the store part of the annotated operation.
>
> I guess this provided ordering is only guaranteed to be observable for
> threads that read the same location with `Acquire` or stronger ordering?
>
> If we start expanding on the orderings, rather than deferring to LKMM,
> we should include this info.

The problem with the word "ordering" is that it is too general, not
specific enough. You need more context to know exactly what the
ordering means.

For example, ordering store A against store B (which comes later in the
code) could mean that the CPU executes A before it executes B. Or it
could mean that a different CPU will see the data from A before it sees
the data from B.

A more explicit description would be helpful.

Alan Stern