|
4 | 4 | <meta charset="utf-8"> |
5 | 5 | <title>Issue 4174: How does [atomics.order] p3 apply when then modification is an initialization?</title> |
6 | 6 | <meta property="og:title" content="Issue 4174: How does [atomics.order] p3 apply when then modification is an initialization?"> |
7 | | -<meta property="og:description" content="C++ library issue. Status: New"> |
| 7 | +<meta property="og:description" content="C++ library issue. Status: SG1"> |
8 | 8 | <meta property="og:url" content="https://cplusplus.github.io/LWG/issue4174.html"> |
9 | 9 | <meta property="og:type" content="website"> |
10 | 10 | <meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png"> |
|
61 | 61 | </head> |
62 | 62 | <body> |
63 | 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> |
| 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#SG1">SG1</a> status.</em></p> |
65 | 65 | <h3 id="4174"><a href="lwg-active.html#4174">4174</a>. How does [atomics.order] p3 apply when then modification is an initialization?</h3> |
66 | | -<p><b>Section:</b> 32.5.4 <a href="https://wg21.link/atomics.order">[atomics.order]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a> |
67 | | - <b>Submitter:</b> jim x <b>Opened:</b> 2024-11-13 <b>Last modified:</b> 2024-11-24</p> |
68 | | -<p><b>Priority: </b>Not Prioritized |
| 66 | +<p><b>Section:</b> 32.5.4 <a href="https://wg21.link/atomics.order">[atomics.order]</a> <b>Status:</b> <a href="lwg-active.html#SG1">SG1</a> |
| 67 | + <b>Submitter:</b> jim x <b>Opened:</b> 2024-11-13 <b>Last modified:</b> 2025-02-07</p> |
| 68 | +<p><b>Priority: </b>3 |
69 | 69 | </p> |
70 | 70 | <p><b>View other</b> <a href="lwg-index-open.html#atomics.order">active issues</a> in [atomics.order].</p> |
71 | 71 | <p><b>View all other</b> <a href="lwg-index.html#atomics.order">issues</a> in [atomics.order].</p> |
72 | | -<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p> |
| 72 | +<p><b>View all issues with</b> <a href="lwg-status.html#SG1">SG1</a> status.</p> |
73 | 73 | <p><b>Discussion:</b></p> |
74 | 74 | <p> |
75 | 75 | Consider this example |
@@ -109,6 +109,66 @@ <h3 id="4174"><a href="lwg-active.html#4174">4174</a>. How does [atomics.order] |
109 | 109 | the store operation in the single total order <i>S</i>? |
110 | 110 | </p> |
111 | 111 |
|
| 112 | +<p><i>[2025-02-07; Reflector poll]</i></p> |
| 113 | + |
| 114 | +<p> |
| 115 | +Set priority to 3 after reflector poll. Send to SG1. |
| 116 | +</p> |
| 117 | +<p> |
| 118 | +LWG found the issue unclear and felt it was missing context that would |
| 119 | +help understand it properly. |
| 120 | +</p> |
| 121 | +<p> |
| 122 | +In |
| 123 | +<a href="https://github.com/cplusplus/CWG/issues/641">cplusplus/CWG/issues/641</a> |
| 124 | +the following example was given: |
| 125 | +<blockquote> |
| 126 | +<pre> |
| 127 | +std::atomic<bool> a = false; |
| 128 | +std::atomic<bool> b = false; |
| 129 | +int v = 0; |
| 130 | +// thread 1: |
| 131 | +a.store(true, seq_cst); |
| 132 | +if(b.load(seq_cst)== false){ |
| 133 | + v = 1; // #1 |
| 134 | +} |
| 135 | +//thread 2: |
| 136 | +b.store(true, seq_cst); |
| 137 | +if(a.load(seq_cst)== false){ |
| 138 | + v = 2; // #2 |
| 139 | +} |
| 140 | +</pre> |
| 141 | +To prove whether #1 and #2 can have data race, we should prove whether |
| 142 | +it's possible that <code class='backtick'>a</code> and <code class='backtick'>b</code> simultaneously read <code class='backtick'>false</code>. |
| 143 | +This proof equals whether there can be a valid single total order in this case. |
| 144 | +To determine the order of <code class='backtick'>b.load</code> and <code class='backtick'>b.store</code> when <code class='backtick'>b.load</code> reads |
| 145 | +the initialization value <code class='backtick'>false</code>, 32.5.4 <a href="https://wg21.link/atomics.order">[atomics.order]</a> p3.3 |
| 146 | +should apply here. |
| 147 | +However, the initialization is not an atomic modification |
| 148 | +such that <code class='backtick'>X</code> cannot be that value. |
| 149 | +</blockquote> |
| 150 | +</p> |
| 151 | + |
| 152 | +<p> |
| 153 | +A possible fix is to amend 32.5.4 <a href="https://wg21.link/atomics.order">[atomics.order]</a>/3.3 to say something |
| 154 | +like this: |
| 155 | +<blockquote> |
| 156 | +(3.3) A and B are not the same atomic read-modify-write operation, and |
| 157 | +<ins>either</ins> |
| 158 | +<ol style="list-style-type: none"> |
| 159 | +<li><ins>(3.3.1)</ins> |
| 160 | +there exists an atomic modification X of M such that A reads |
| 161 | +the value stored by X and X precedes B in the modification order of M<ins>, |
| 162 | +or</ins> |
| 163 | +</li> |
| 164 | +<li><ins>(3.3.2) |
| 165 | +A reads the initial value of X and B modifies M</ins>, or |
| 166 | +</li> |
| 167 | +</ol> |
| 168 | +</blockquote> |
| 169 | +</p> |
| 170 | + |
| 171 | + |
112 | 172 |
|
113 | 173 | <p id="res-4174"><b>Proposed resolution:</b></p> |
114 | 174 | <p> |
|
0 commit comments