This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.

4244. Whether the spuriously failed comparison applies to compare_exchange_strong is unclear

Section: 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 false then, after the atomic operation, the value in expected is replaced by the value read from the value referenced by *ptr during 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.

However, we don't explicitly say whether the strong version can have the spuriously failed comparison. The status quo is that we can only infer the point from the name, namely, the strong version should have a stronger guarantee than the weak version.

Suggested resolution:

Explicitly specify whether compare_exchange_strong can have the spurious failed comparison.

Proposed resolution: