Skip to content

Incorrect explanation of Sequential Consistency #479

@vdrn

Description

@vdrn

Quoting from the "Sequential Consistency" part of Atomics:

Intuitively, a sequentially consistent operation cannot be reordered: all accesses on one thread that happen before and after a SeqCst access stay before and after it.

I believe this is wrong, as it states that "all accesses" (which presumably includes data and weaker atomic accesses) cannot be reordered past SeqCst access.

Only other SeqCst accesses cannot be reordered with SeqCst access.
For example, data (and relaxed atomic) accesses can be reordered:

  • before SeqCst stores
  • after SeqCst loads

So, "all accesses" should be replaced with "all SeqCst accesses".

From C++ standard (page 1525, par 7):

In many cases, memory_order::seq_cst atomic operations are reorderable with respect to other atomic operations performed by the same thread.

From Rust Atomics and Locks

The strongest memory ordering is sequentially consistent ordering: Ordering::SeqCst. It includes all the guarantees of acquire ordering (for loads) and release ordering (for stores), and also guarantees a globally consistent order of operations.

This means that every single operation using SeqCst ordering within a program is part of a single total order that all threads agree on. This total order is consistent with the total modification order of each individual variable.

Myth: Sequentially consistent memory ordering can be used for a "release-load" or an "acquire-store."

While SeqCst can stand in for Acquire or Release, it is not a way to somehow create an acquire-store or release-load. Those remain nonexistent. Release only applies to store operations, and acquire only to load operations.

For example, a Release-store does not form any release-acquire relationship with a SeqCst-store. If you need them to be part of a globally consistent order, both operations will have to use SeqCst.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions