|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | +<meta charset="utf-8"> |
| 5 | +<title>Issue 4244: Whether the spuriously failed comparison applies to compare_exchange_strong is unclear</title> |
| 6 | +<meta property="og:title" content="Issue 4244: Whether the spuriously failed comparison applies to compare_exchange_strong is unclear"> |
| 7 | +<meta property="og:description" content="C++ library issue. Status: New"> |
| 8 | +<meta property="og:url" content="https://cplusplus.github.io/LWG/issue4244.html"> |
| 9 | +<meta property="og:type" content="website"> |
| 10 | +<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png"> |
| 11 | +<meta property="og:image:alt" content="C++ logo"> |
| 12 | +<style> |
| 13 | + p {text-align:justify} |
| 14 | + li {text-align:justify} |
| 15 | + pre code.backtick::before { content: "`" } |
| 16 | + pre code.backtick::after { content: "`" } |
| 17 | + blockquote.note |
| 18 | + { |
| 19 | + background-color:#E0E0E0; |
| 20 | + padding-left: 15px; |
| 21 | + padding-right: 15px; |
| 22 | + padding-top: 1px; |
| 23 | + padding-bottom: 1px; |
| 24 | + } |
| 25 | + ins {background-color:#A0FFA0} |
| 26 | + del {background-color:#FFA0A0} |
| 27 | + table.issues-index { border: 1px solid; border-collapse: collapse; } |
| 28 | + table.issues-index th { text-align: center; padding: 4px; border: 1px solid; } |
| 29 | + table.issues-index td { padding: 4px; border: 1px solid; } |
| 30 | + table.issues-index td:nth-child(1) { text-align: right; } |
| 31 | + table.issues-index td:nth-child(2) { text-align: left; } |
| 32 | + table.issues-index td:nth-child(3) { text-align: left; } |
| 33 | + table.issues-index td:nth-child(4) { text-align: left; } |
| 34 | + table.issues-index td:nth-child(5) { text-align: center; } |
| 35 | + table.issues-index td:nth-child(6) { text-align: center; } |
| 36 | + table.issues-index td:nth-child(7) { text-align: left; } |
| 37 | + table.issues-index td:nth-child(5) span.no-pr { color: red; } |
| 38 | + @media (prefers-color-scheme: dark) { |
| 39 | + html { |
| 40 | + color: #ddd; |
| 41 | + background-color: black; |
| 42 | + } |
| 43 | + ins { |
| 44 | + background-color: #225522 |
| 45 | + } |
| 46 | + del { |
| 47 | + background-color: #662222 |
| 48 | + } |
| 49 | + a { |
| 50 | + color: #6af |
| 51 | + } |
| 52 | + a:visited { |
| 53 | + color: #6af |
| 54 | + } |
| 55 | + blockquote.note |
| 56 | + { |
| 57 | + background-color: rgba(255, 255, 255, .10) |
| 58 | + } |
| 59 | + } |
| 60 | +</style> |
| 61 | +</head> |
| 62 | +<body> |
| 63 | +<hr> |
| 64 | +<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#New">New</a> status.</em></p> |
| 65 | +<h3 id="4244"><a href="lwg-active.html#4244">4244</a>. Whether the spuriously failed comparison applies to <code class='backtick'>compare_exchange_strong</code> is unclear</h3> |
| 66 | +<p><b>Section:</b> 32.5.7.2 <a href="https://wg21.link/atomics.ref.ops">[atomics.ref.ops]</a>, 32.5.8.2 <a href="https://wg21.link/atomics.types.operations">[atomics.types.operations]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a> |
| 67 | + <b>Submitter:</b> jim x <b>Opened:</b> 2025-04-17 <b>Last modified:</b> 2025-04-21</p> |
| 68 | +<p><b>Priority: </b>Not Prioritized |
| 69 | +</p> |
| 70 | +<p><b>View other</b> <a href="lwg-index-open.html#atomics.ref.ops">active issues</a> in [atomics.ref.ops].</p> |
| 71 | +<p><b>View all other</b> <a href="lwg-index.html#atomics.ref.ops">issues</a> in [atomics.ref.ops].</p> |
| 72 | +<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p> |
| 73 | +<p><b>Discussion:</b></p> |
| 74 | +<p> |
| 75 | +Both <code class='backtick'>compare_exchange_strong</code> and <code class='backtick'>compare_exchange_weak</code> share the same specified rule |
| 76 | +</p> |
| 77 | +<blockquote style="border-left: 3px solid #ccc;padding-left: 15px;"> |
| 78 | +<p> |
| 79 | +If and only if the comparison is <code class='backtick'>false</code> then, after the atomic operation, the value in |
| 80 | +<code class='backtick'>expected</code> is replaced by the value read from the value referenced by <code class='backtick'>*ptr</code> during the |
| 81 | +atomic comparison. |
| 82 | +</p> |
| 83 | +</blockquote> |
| 84 | +<p> |
| 85 | +However, there is a remark for the weak version |
| 86 | +</p> |
| 87 | +<blockquote style="border-left: 3px solid #ccc;padding-left: 15px;"> |
| 88 | +<p> |
| 89 | +A weak compare-and-exchange operation may fail spuriously. |
| 90 | +</p> |
| 91 | +</blockquote> |
| 92 | +<p> |
| 93 | +That is, even when the contents of memory referred to by <code class='backtick'>expected</code> and <code class='backtick'>ptr</code> are equal, |
| 94 | +it may return <code class='backtick'>false</code> and store back to expected the same memory contents that were |
| 95 | +originally there. |
| 96 | +<p/> |
| 97 | +However, we don't explicitly say whether the strong version can have the spuriously failed |
| 98 | +comparison. The status quo is that we can only infer the point from the name, namely, the |
| 99 | +strong version should have a stronger guarantee than the weak version. |
| 100 | +<p/> |
| 101 | +<b>Suggested resolution:</b> |
| 102 | +<p/> |
| 103 | +Explicitly specify whether <code class='backtick'>compare_exchange_strong</code> can have the spurious failed comparison. |
| 104 | +</p> |
| 105 | + |
| 106 | + |
| 107 | +<p id="res-4244"><b>Proposed resolution:</b></p> |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | +</body> |
| 114 | +</html> |
0 commit comments