forked from lwg/issues
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New issue from jim x: "The load and store operation in §[atomics.orde…
…r] p1 is ambiguous"
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 §[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) — <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) — <tt>memory_order::consume</tt>: a load operation performs a consume operation on the affected memory location. | ||
[…]</p></li> | ||
<li><p>(1.4) — <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<int> 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> |