|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4519" status="New"> |
| 5 | +<title>No formal rule associates the total order of a mutex object with the rule for modification order</title> |
| 6 | +<section><sref ref="[thread.mutex.requirements.mutex.general]"/></section> |
| 7 | +<submitter>jim x</submitter> |
| 8 | +<date>05 Feb 2026</date> |
| 9 | +<priority>99</priority> |
| 10 | + |
| 11 | +<discussion> |
| 12 | +<p> |
| 13 | +<sref ref="[thread.mutex.requirements.mutex.general]"/> p4 says (emphasis mine): |
| 14 | +</p> |
| 15 | +<blockquote> |
| 16 | +<p> |
| 17 | +For purposes of determining the existence of a data race, these behave as <b>atomic operations</b> |
| 18 | +(<sref ref="[intro.multithread]"/>). The lock and unlock operations on a single |
| 19 | +mutex appears to occur in <b>a single total order</b>. |
| 20 | +</p> |
| 21 | +</blockquote> |
| 22 | +<p> |
| 23 | +The second note in <sref ref="[thread.mutex.requirements.mutex]"/> p4 |
| 24 | +</p> |
| 25 | +<blockquote><p> |
| 26 | +[<i>Note 2</i>: This can be viewed as the modification order of the mutex. — <i>end note</i>] |
| 27 | +</p></blockquote> |
| 28 | +<p> |
| 29 | +wants to inform the reader to interpret the single total order as a modification order. The review in |
| 30 | +LWG <iref ref="4475"/> says: |
| 31 | +</p> |
| 32 | +<blockquote><p> |
| 33 | +For atomic objects, the modification order is already a single total order, `seq_cst` or not. This isn't a useful change. |
| 34 | +</p></blockquote> |
| 35 | +<p> |
| 36 | +This implies that we want the single total order of a mutex object to be considered as the modification |
| 37 | +order of an atomic object for defining the order of the single total order by existing rules (especially, |
| 38 | +<sref ref="[intro.races]"/> p11-p14). |
| 39 | +<p/> |
| 40 | +However, the wording in <sref ref="[thread.mutex.requirements.mutex.general]"/> p1 (emphasis mine) |
| 41 | +</p> |
| 42 | +<blockquote><p> |
| 43 | +In this description, `m` denotes <b>an object of a mutex type</b>. |
| 44 | +</p></blockquote> |
| 45 | +<p> |
| 46 | +strongly implies that there is a difference between atomic objects and mutex objects. |
| 47 | +Except for the note, there is no formal wording to state that `lock()` and `unlock()` operations are |
| 48 | +modifications to the mutex object as if they were modifications to an atomic object for the purpose |
| 49 | +of determining the total order, that is, the rules defined in <sref ref="[intro.races]"/> that |
| 50 | +applies to an atomic object can also apply to an mutex object. |
| 51 | +</p> |
| 52 | +</discussion> |
| 53 | + |
| 54 | +<resolution> |
| 55 | +<p> |
| 56 | +This wording is relative to <paper num="N5032"/>. |
| 57 | +</p> |
| 58 | + |
| 59 | +<ol> |
| 60 | +<li><p>Modify <sref ref="[thread.mutex.requirements.mutex.general]"/> as indicated:</p> |
| 61 | + |
| 62 | +<blockquote> |
| 63 | +<p> |
| 64 | +-4- The implementation provides lock and unlock operations, as described below. For purposes of determining |
| 65 | +the existence of a data race, these behave as atomic operations (<sref ref="[intro.multithread]"/>) |
| 66 | +<ins>as if they were modifications to an atomic object</ins>. The lock and unlock operations on a single mutex |
| 67 | +appears to occur in a single total order<ins>, this can be viewed as the modification order of the atomic object</ins>. |
| 68 | +</p> |
| 69 | +</blockquote> |
| 70 | +</li> |
| 71 | + |
| 72 | +</ol> |
| 73 | +</resolution> |
| 74 | + |
| 75 | +</issue> |
0 commit comments