1474. weak compare-and-exchange confusion

Section: 32.6.1 [atomics.types.operations] Status: C++11 Submitter: INCITS Opened: 2010-08-25 Last modified: 2017-06-16

Priority: Not Prioritized

View all other issues in [atomics.types.operations].

View all issues with C++11 status.

Duplicate of: 1470, 1475, 1476, 1477

Discussion:

Addresses US-175, US-165, CH-23, GB-135

99 [atomics.types.operations.req] p. 25: The first sentence is grammatically incorrect.

[ 2010-10-28 Daniel adds: ]

Duplicate issue 1475 also has a proposed resolution, but both issues are resolved with below proposed resolution.

[ 2011-02-15 Howard fixes numbering, Hans improves the wording ]

[2011-02-24 Reflector discussion]

Moved to Tentatively Ready after 6 votes.

Proposed resolution:

  1. Change 99 [atomics.types.operations.req] p. 23 as indicated:

    [ Note: For example, tThe effect of the compare-and-exchange operationsatomic_compare_exchange_strong is

    if (memcmp(object, expected, sizeof(*object)) == 0)
      memcpy(object, &desired, sizeof(*object));
    else
      memcpy(expected, object, sizeof(*object));
    

    end note ] [..]

  2. Change 99 [atomics.types.operations.req] p. 25 as indicated:

    25 Remark: The weak compare-and-exchange operations may fail spuriously, that is, return false while leaving the contents of memory pointed to by expected before the operation is the same that same as that of the object and the same as that of expected after the operationA weak compare-and-exchange operation may fail spuriously. That is, even when the contents of memory referred to by expected and object are equal, it may return false and store back to expected the same memory contents that were originally there.. [ Note: This spurious failure enables implementation of compare-and-exchange on a broader class of machines, e.g., loadlocked store-conditional machines. A consequence of spurious failure is that nearly all uses of weak compare-and-exchange will be in a loop.

    When a compare-and-exchange is in a loop, the weak version will yield better performance on some platforms. When a weak compare-and-exchange would require a loop and a strong one would not, the strong one is preferable. — end note ]