compare_exchange_strong is unclearSection: 32.5.7.2 [atomics.ref.ops], 32.5.8.2 [atomics.types.operations] Status: New Submitter: jim x Opened: 2025-04-17 Last modified: 2025-04-21
Priority: Not Prioritized
View other active issues in [atomics.ref.ops].
View all other issues in [atomics.ref.ops].
View all issues with New 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.
Proposed resolution: