<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1474: weak compare-and-exchange confusion</title>
<meta property="og:title" content="Issue 1474: weak compare-and-exchange confusion">
<meta property="og:description" content="C++ library issue. Status: C++11">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1474.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#C++11">C++11</a> status.</em></p>
<h3 id="1474"><a href="lwg-defects.html#1474">1474</a>. weak compare-and-exchange confusion</h3>
<p><b>Section:</b> 32.5.8.2 <a href="https://wg21.link/atomics.types.operations">[atomics.types.operations]</a> <b>Status:</b> <a href="lwg-active.html#C++11">C++11</a>
 <b>Submitter:</b> INCITS <b>Opened:</b> 2010-08-25 <b>Last modified:</b> 2017-06-15</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View other</b> <a href="lwg-index-open.html#atomics.types.operations">active issues</a> in [atomics.types.operations].</p>
<p><b>View all other</b> <a href="lwg-index.html#atomics.types.operations">issues</a> in [atomics.types.operations].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++11">C++11</a> status.</p>
<p><b>Duplicate of:</b> <a href="lwg-closed.html#1470" title="&quot;Same-ness&quot; curiosities (Status: Dup)">1470</a>, <a href="lwg-closed.html#1475" title="weak compare-and-exchange confusion II (Status: Dup)">1475</a>, <a href="lwg-closed.html#1476" title="Meaningless specification of spurious failure (Status: Dup)">1476</a>, <a href="lwg-closed.html#1477" title="weak compare-and-exchange confusion III (Status: Dup)">1477</a></p>
<p><b>Discussion:</b></p>



<p><b>Addresses US-175, US-165, CH-23, GB-135</b></p>
<p>
99 [atomics.types.operations.req] p. 25: The first sentence is grammatically incorrect.
</p>
<p><i>[
2010-10-28 Daniel adds:
]</i></p>

<p>
Duplicate issue <a href="lwg-closed.html#1475" title="weak compare-and-exchange confusion II (Status: Dup)">1475</a><sup><a href="https://cplusplus.github.io/LWG/issue1475" title="Latest snapshot">(i)</a></sup> also has a proposed resolution, but both issues are resolved with
below proposed resolution.
</p>

<p><i>[
2011-02-15 Howard fixes numbering, Hans improves the wording
]</i></p>


<p><i>[2011-02-24 Reflector discussion]</i></p>

<p>
Moved to Tentatively Ready after 6 votes.
</p> 


<p id="res-1474"><b>Proposed resolution:</b></p>
<ol>
<li>
<p>Change 99 [atomics.types.operations.req] p. 23 as indicated:</p>

<blockquote><p>
[ <em>Note</em>: <ins>For example, t</ins><del>T</del>he effect of 
<del>the compare-and-exchange operations</del><ins><code>atomic_compare_exchange_strong</code></ins> is
</p><blockquote><pre>
if (memcmp(object, expected, sizeof(*object)) == 0)
  memcpy(object, &amp;desired, sizeof(*object));
else
  memcpy(expected, object, sizeof(*object));
</pre></blockquote>
<p> &mdash; <em>end note</em> ] [..]</p>
</blockquote>
</li>

<li>
<p>Change 99 [atomics.types.operations.req] p. 25 as indicated:</p>
<blockquote><p>
25 <em>Remark</em>: <del>The weak compare-and-exchange operations may fail spuriously, that is, return false while
leaving the contents of memory pointed to by <code>expected</code> before the operation is the same that same
as that of the <code>object</code> and the same as that of <code>expected</code> after the operation</del><ins>A weak 
compare-and-exchange operation may fail spuriously. That is, even when the contents of memory referred to by 
<code>expected</code> and <code>object</code> are equal, it may return false and store back to <code>expected</code> the same 
memory contents that were originally there.</ins>. [ <em>Note</em>: 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.
<p/>
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. &mdash; <em>end note</em> ]
</p>
</blockquote>
</li>
</ol>





</body>
</html>
