Skip to content

Lift unnecessary restriction on CAS failure ordering #68464

Description

@tmiasko

Currently compare_exchange requires the failure ordering to "be equivalent to
or weaker than a success ordering". On the other hand C11/C++11 requires only
that "failure shall be no stronger than the success", which arguably means that
one can write e.g. compare_exchange(..., Release, Acquire) in C/C++ but not in Rust.

Arguably, because neither C11 standard nor C++11 standard defines what it means
for an ordering to be stronger from another. When the issue was raised in
LWG2445, the proposed and accepted resolution was to lift those restrictions
altogether, leaving only requirement that "the failure argument shall not be
memory_order_release nor memory_order_acq_rel".

It would be beneficial to remove success/failure ordering restrictions for
reasons described in C++ proposal P0418r2.

EDIT: Restrictions were lifted in clang & LLVM:

Activity

  1. tmiasko commented on Jul 17, 2020

    @tmiasko
    ContributorAuthor

    Blocked on https://bugs.llvm.org/show_bug.cgi?id=33332. The cmpxchg release acquire is accepted by LLVM but miscompiled on AArch64.

  2. self-assigned this
    on May 26, 2022
  3. m-ou-se commented on May 26, 2022

    @m-ou-se
    Member

    @tmiasko I'm about to send a PR that implements this.

  4. tmiasko commented on May 26, 2022

    @tmiasko
    ContributorAuthor

    @m-ou-se I do have implementation ready as well, but that's fine, I can review instead :-).

  5. m-ou-se commented on May 26, 2022

    @m-ou-se
    Member

    I split it in a PR that renames the intrinsics first, and a separate PR for exposing the new ordering combinations afterwards.

  6. assigned and unassigned on May 29, 2022
  7. m-ou-se commented on Jun 22, 2022

    @m-ou-se
    Member

    Looks like llvm 12 doesn't support this: #98383 (comment)

    Can we make things conditionally fall back to a stronger ordering depending on the llvm version? I don't think we do anything like that in the library right now, but maybe the compiler already does things differently for different llvm versions?

  8. m-ou-se commented on Jun 22, 2022

    @m-ou-se
    Member

    Ah yes, some code checks llvm_util::get_version() < (13, 0, 0). I suppose Builder::atomic_cmpxchg could check the same, and upgrade the ordering if necessary in that case.

  9. m-ou-se commented on Jun 22, 2022

    @m-ou-se
    Member

    Did exactly that in #98385

  10. m-ou-se commented on Jun 22, 2022

    @m-ou-se
    Member
  11. added a commit that references this issue on Jun 26, 2022
  12. added 4 commits that reference this issue on Jun 26, 2022
  13. added 2 commits that reference this issue on Jul 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-concurrencyArea: ConcurrencyC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-langRelevant to the language teamT-libs-api[DEPRECATED; DO NOT USE]

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions