This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of Tentatively NAD status.
compare_exchange_strong is unclearSection: 32.5.7.2 [atomics.ref.ops], 32.5.8.2 [atomics.types.operations] Status: Tentatively NAD Submitter: jim x Opened: 2025-04-17 Last modified: 2025-10-20
Priority: Not Prioritized
View other active issues in [atomics.ref.ops].
View all other issues in [atomics.ref.ops].
View all issues with Tentatively NAD status.
Discussion:
Both compare_exchange_strong and compare_exchange_weak share the same specified rule
If and only if the comparison is
falsethen, after the atomic operation, the value inexpectedis replaced by the value read from the value referenced by*ptrduring the atomic comparison.
However, there is a remark for the weak version
A weak compare-and-exchange operation may fail spuriously.
That is, even when the contents of memory referred to by expected and ptr are equal,
it may return false and store back to expected the same memory contents that were
originally there.
compare_exchange_strong can have the spurious failed comparison.
[2025-10-20; Reflector poll. Status changed: New → Tentatively NAD.]
"The Effects: explain the behaviour, and don't allow for spurious failures."
"The Remarks: are normative and are explicitly adding permission to fail spuriously. Absent such permission, the specification for strong operations is clear and has no spurious failures."
Proposed resolution: