|
1 | 1 | <?xml version='1.0' encoding='utf-8' standalone='no'?>
|
2 | 2 | <!DOCTYPE issue SYSTEM "lwg-issue.dtd">
|
3 | 3 |
|
4 |
| -<issue num="4174" status="New"> |
| 4 | +<issue num="4174" status="SG1"> |
5 | 5 | <title>How does [atomics.order] p3 apply when then modification is an initialization?</title>
|
6 | 6 | <section><sref ref="[atomics.order]"/></section>
|
7 | 7 | <submitter>jim x</submitter>
|
8 | 8 | <date>13 Nov 2024</date>
|
9 |
| -<priority>99</priority> |
| 9 | +<priority>3</priority> |
10 | 10 |
|
11 | 11 | <discussion>
|
12 | 12 | <p>
|
@@ -46,6 +46,65 @@ According to <sref ref="[atomics.types.operations]"/> p3 (emphasize mine)
|
46 | 46 | So, how does <sref ref="[atomics.order]"/> p3 apply to this example such that the load operation precedes
|
47 | 47 | the store operation in the single total order <i>S</i>?
|
48 | 48 | </p>
|
| 49 | + |
| 50 | +<note>2025-02-07; Reflector poll</note> |
| 51 | +<p> |
| 52 | +Set priority to 3 after reflector poll. Send to SG1. |
| 53 | +</p> |
| 54 | +<p> |
| 55 | +LWG found the issue unclear and felt it was missing context that would |
| 56 | +help understand it properly. |
| 57 | +</p> |
| 58 | +<p> |
| 59 | +In |
| 60 | +<a href="https://github.com/cplusplus/CWG/issues/641">cplusplus/CWG/issues/641</a> |
| 61 | +the following example was given: |
| 62 | +<blockquote> |
| 63 | +<pre> |
| 64 | +std::atomic<bool> a = false; |
| 65 | +std::atomic<bool> b = false; |
| 66 | +int v = 0; |
| 67 | +// thread 1: |
| 68 | +a.store(true, seq_cst); |
| 69 | +if(b.load(seq_cst)== false){ |
| 70 | + v = 1; // #1 |
| 71 | +} |
| 72 | +//thread 2: |
| 73 | +b.store(true, seq_cst); |
| 74 | +if(a.load(seq_cst)== false){ |
| 75 | + v = 2; // #2 |
| 76 | +} |
| 77 | +</pre> |
| 78 | +To prove whether #1 and #2 can have data race, we should prove whether |
| 79 | +it's possible that `a` and `b` simultaneously read `false`. |
| 80 | +This proof equals whether there can be a valid single total order in this case. |
| 81 | +To determine the order of `b.load` and `b.store` when `b.load` reads |
| 82 | +the initialization value `false`, <sref ref="[atomics.order]"/> p3.3 |
| 83 | +should apply here. |
| 84 | +However, the initialization is not an atomic modification |
| 85 | +such that `X` cannot be that value. |
| 86 | +</blockquote> |
| 87 | +</p> |
| 88 | + |
| 89 | +<p> |
| 90 | +A possible fix is to amend <sref ref="[atomics.order]"/>/3.3 to say something |
| 91 | +like this: |
| 92 | +<blockquote> |
| 93 | +(3.3) A and B are not the same atomic read-modify-write operation, and |
| 94 | +<ins>either</ins> |
| 95 | +<ol style="list-style-type: none"> |
| 96 | +<li><ins>(3.3.1)</ins> |
| 97 | +there exists an atomic modification X of M such that A reads |
| 98 | +the value stored by X and X precedes B in the modification order of M<ins>, |
| 99 | +or</ins> |
| 100 | +</li> |
| 101 | +<li><ins>(3.3.2) |
| 102 | +A reads the initial value of X and B modifies M</ins>, or |
| 103 | +</li> |
| 104 | +</ol> |
| 105 | +</blockquote> |
| 106 | +</p> |
| 107 | + |
49 | 108 | </discussion>
|
50 | 109 |
|
51 | 110 | <resolution>
|
|
0 commit comments