Skip to content

Commit 43fe0e6

Browse files
committed
New issue from jim x: "How are evaluations occurring within a store and a load operation ordered where the store synchronized with the load"
1 parent 3b42c65 commit 43fe0e6

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

xml/issue4321.xml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4321" status="New">
5+
<title>How are evaluations occurring within a store and a load operation ordered where the store synchronized with the load</title>
6+
<section>
7+
<sref ref="[atomics.types.operations]"/>
8+
</section>
9+
<submitter>jim x</submitter>
10+
<date>20 Aug 2025</date>
11+
<priority>99</priority>
12+
13+
<discussion>
14+
<p>
15+
Consider this example:
16+
</p>
17+
<blockquote><pre>
18+
std::atomic&lt;int&gt; v = 0;
19+
// thread 1:
20+
v.store(1, memory_order::release); // #1
21+
// thread 2:
22+
v.load(memory_order::acquire); // #2
23+
</pre></blockquote>
24+
<p>
25+
Say, `#2` reads the value written by `#1`, `#1` synchronizes with `#2`. According to <sref ref="[intro.races]"/> p7:
26+
</p>
27+
<blockquote>
28+
<p>
29+
An evaluation <i>A</i> <i>happens before an evaluation</i> <i>B</i> (or, equivalently, <i>B</i>
30+
happens after <i>A</i>) if either
31+
</p>
32+
<ol style="list-style-type: none">
33+
<li><p>(7.1) &mdash; [&hellip;]</p></li>
34+
<li><p>(7.2) &mdash; <i>A</i> synchronizes with <i>B</i>, or</p></li>
35+
<li><p>(7.3) &mdash; [&hellip;]</p></li>
36+
</ol>
37+
</blockquote>
38+
<p>
39+
So, `#1` happens before <i>B</i>. However, <sref ref="[intro.execution]"/> p12 says:
40+
</p>
41+
<blockquote>
42+
<p>
43+
For each
44+
</p>
45+
<ol style="list-style-type: none">
46+
<li><p>(12.1) &mdash; function invocation,</p></li>
47+
<li><p>(12.2) &mdash; [&hellip;]</p></li>
48+
<li><p>(12.3) &mdash; [&hellip;]</p></li>
49+
</ol>
50+
<p>
51+
<i>F</i>, each evaluation that does not occur within <i>F</i> but is evaluated
52+
on the same thread and as part of the same signal handler (if any) is either
53+
sequenced before all evaluations that occur within <i>F</i> or sequenced after
54+
all evaluations that occur within <i>F</i>;
55+
</p>
56+
</blockquote>
57+
<p>
58+
Because both `v.store(...)` and `v.load(...)` are function invocations, and we can think that the member
59+
functions comprise some evaluations to form the operation, therefore, how are these evaluations that
60+
occur within the `store` ordered with those within the `load`?
61+
<p/>
62+
The rule only says the `store` synchronizes with the `load`, hence, the evaluation of the function
63+
call expression `v.store(...)` happens before the evaluation of the function call expression `v.load(...)`,
64+
but how about these evaluations occurring within these functions?
65+
</p>
66+
</discussion>
67+
68+
<resolution>
69+
</resolution>
70+
71+
</issue>

0 commit comments

Comments
 (0)