Skip to content

Commit 575029f

Browse files
committed
New issue from jim x: "The description to single total order in [thread.mutex.requirements.mutex.general] is hollow"
1 parent fa86cec commit 575029f

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

xml/issue4475.xml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4475" status="New">
5+
<title>The description to single total order in [thread.mutex.requirements.mutex.general] is hollow</title>
6+
<section><sref ref="[thread.mutex.requirements.mutex.general]"/></section>
7+
<submitter>jim x</submitter>
8+
<date>14 Nov 2025</date>
9+
<priority>99</priority>
10+
11+
<discussion>
12+
<p>
13+
<sref ref="[thread.mutex.requirements.mutex.general]"/> p4 says:
14+
</p>
15+
<blockquote style="border-left: 3px solid #ccc;padding-left: 15px;">
16+
<p>
17+
For purposes of determining the existence of a data race, these behave as atomic operations
18+
(<sref ref="[intro.multithread]"/>). The lock and unlock operations on a single mutex appears
19+
to occur in a single total order.
20+
</p>
21+
</blockquote>
22+
<p>
23+
Even for atomic operations, the precondition for ordering them in a single total order is that
24+
they must be `memory_order::seq_cst` operations, such that we can form the total order to reason.
25+
<p/>
26+
Put aside the fact that we impose the preconditions on `unlock` and `lock`. Is this a possible
27+
total order if `lock` reads `unlock_1`, but there is a `unlock_2` between them
28+
</p>
29+
<blockquote>
30+
<p>
31+
`unlock_1` &lt; `unlock_2` &lt; `lock`
32+
</p>
33+
</blockquote>
34+
<p>
35+
First, although we have said that lock and unlock operations behave as atomic operations,
36+
and `lock` reads `unlock_1`, meaning that `unlock_1` is coherence-ordered before `lock`,
37+
however, we don't specify that they are `memory_order::seq_cst` operations, so
38+
<sref ref="[atomics.order]"/> p4 doesn't apply here
39+
</p>
40+
<blockquote style="border-left: 3px solid #ccc;padding-left: 15px;">
41+
<p>
42+
Second, for every pair of atomic operations <tt><i>A</i></tt> and <tt><i>B</i></tt> on an
43+
object <tt><i>M</i></tt>, where <tt><i>A</i></tt> is coherence-ordered before <tt><i>B</i></tt>,
44+
the following four conditions are required to be satisfied by <tt><i>S</i></tt>:
45+
</p>
46+
<ul style="list-style-type: none">
47+
<li>(4.1) &mdash;
48+
if <tt><i>A</i></tt> and <tt><i>B</i></tt> are both `memory_order::seq_cst` operations,
49+
then <tt><i>A</i></tt> precedes <tt><i>B</i></tt> in <tt><i>S</i></tt>; and
50+
</li>
51+
</ul>
52+
</blockquote>
53+
<p>
54+
So, it is not helpful to decide that `unlock_1` precedes `lock` in a single total order.
55+
Similarly, excluding `unlock_1` &lt; `unlock_2` &lt; `lock` is not possible.
56+
<p/>
57+
<b>Suggested resolution:</b>
58+
<p/>
59+
The lock and unlock operations on a single mutex appears to occur in a single total order;
60+
for this purpose, these operations are considered as `memory_order::seq_cst` operations
61+
</p>
62+
</discussion>
63+
64+
<resolution>
65+
<p>
66+
This wording is relative to <paper num="N5014"/>.
67+
</p>
68+
69+
<ol>
70+
<li><p>Modify <sref ref="[thread.mutex.requirements.mutex.general]"/> as indicated:</p>
71+
72+
<blockquote>
73+
<p>
74+
-4- The implementation provides lock and unlock operations, as described below. For purposes of determining
75+
the existence of a data race, these behave as atomic operations (<sref ref="[intro.multithread]"/>).
76+
The lock and unlock operations on a single mutex appears to occur in a single total order<ins>; for
77+
this purpose, these operations are considered as `memory_order::seq_cst` operations</ins>.
78+
</p>
79+
</blockquote>
80+
</li>
81+
</ol>
82+
</resolution>
83+
84+
</issue>

0 commit comments

Comments
 (0)