Skip to content

Commit

Permalink
New issue from jim x: "The load and store operation in §[atomics.orde…
Browse files Browse the repository at this point in the history
…r] p1 is ambiguous"
  • Loading branch information
Dani-Hub committed Nov 4, 2023
1 parent 324a840 commit 50998c7
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions xml/issue4004.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version='1.0' encoding='utf-8' standalone='no'?>
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">

<issue num="4004" status="New">
<title>The load and store operation in &sect;[atomics.order] p1 is ambiguous</title>
<section><sref ref="[atomics.order]"/></section>
<submitter>jim x</submitter>
<date>30 Oct 2023</date>
<priority>99</priority>

<discussion>
<p>
<sref ref="[atomics.order]"/> p1 says:
</p>
<blockquote style="border-left: 3px solid #ccc;padding-left: 15px;">
<ol style="list-style-type: none">
<li><p>(1.2) &mdash; <tt>memory_order::release</tt>, <tt>memory_order::acq_rel</tt>, and <tt>memory_order::seq_cst</tt>: a store operation
performs a release operation on the affected memory location.</p></li>
<li><p>(1.3) &mdash; <tt>memory_order::consume</tt>: a load operation performs a consume operation on the affected memory location.
[&hellip;]</p></li>
<li><p>(1.4) &mdash; <tt>memory_order::acquire</tt>, <tt>memory_order::acq_rel</tt>, and <tt>memory_order::seq_cst</tt>: a
load operation performs an acquire operation on the affected memory location.</p></li>
</ol>
</blockquote>
<p>
What do the store and load operations intend to mean in this context? If there is no extra specification,
it is easy to consider them as the operations performed by the non-static member functions "store" and "load"
defined in the <tt>atomic</tt> class (template).
<p/>
<sref ref="[atomics.order]"/> p2 says
</p>
<blockquote style="border-left: 3px solid #ccc;padding-left: 15px;">
<p>
An atomic operation <i>A</i> that performs a release operation on an atomic object <i>M</i> synchronizes with
an atomic operation <i>B</i> that performs an acquire operation on <i>M</i> and takes its value from any side
effect in the release sequence headed by <i>A</i>.
</p>
</blockquote>
<p>
According to the above interpretation, <i>A</i> is an operation performed by the non-static member function
<tt>store</tt>, however, I think the following example can establish the synchronization relationship
</p>
<blockquote><pre>
std::atomic&lt;int&gt; x{0};
Thread 1:
int expected = 0;
x.compare_exchange_strong(expected, 1, memory_order::release, memory_order::relaxed ); //#1

Thread 2:
int expected = 1;
while(x.compare_exchange_strong( expected, 2, memory_order::acquire, memory_order::relaxed )){} // #2
</pre></blockquote>
<p>
Assuming the RMW operations are successful in the two threads, I think <tt>#1</tt> intends to perform a
release operation while <tt>#2</tt> performs an acquire operation, and hence they can establish the
synchronization relationship, however, they both are RMW operations.
<p/>
It should be clearly defined which are store operations and which are load operations.
</p>
</discussion>

<resolution>
</resolution>

</issue>

0 comments on commit 50998c7

Please sign in to comment.