<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 936: Mutex type overspecified</title>
<meta property="og:title" content="Issue 936: Mutex type overspecified">
<meta property="og:description" content="C++ library issue. Status: LEWG">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue936.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#LEWG">LEWG</a> status.</em></p>
<h3 id="936"><a href="lwg-active.html#936">936</a>. Mutex type overspecified</h3>
<p><b>Section:</b> 32.6.4 <a href="https://wg21.link/thread.mutex.requirements">[thread.mutex.requirements]</a> <b>Status:</b> <a href="lwg-active.html#LEWG">LEWG</a>
 <b>Submitter:</b> Pete Becker <b>Opened:</b> 2008-12-05 <b>Last modified:</b> 2017-03-01</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View other</b> <a href="lwg-index-open.html#thread.mutex.requirements">active issues</a> in [thread.mutex.requirements].</p>
<p><b>View all other</b> <a href="lwg-index.html#thread.mutex.requirements">issues</a> in [thread.mutex.requirements].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#LEWG">LEWG</a> status.</p>
<p><b>Duplicate of:</b> <a href="lwg-active.html#961" title="Various threading bugs #11 (Status: LEWG)">961</a></p>
<p><b>Discussion:</b></p>



<p>
32.6.4 <a href="https://wg21.link/thread.mutex.requirements">[thread.mutex.requirements]</a> describes the requirements for a type to be
a "Mutex type". A Mutex type can be used as the template argument for
the <code>Lock</code> type that's passed to <code>condition_variable_any::wait</code> (although
<code>Lock</code> seems like the wrong name here, since <code>Lock</code> is given a different
formal meaning in 32.6.5 <a href="https://wg21.link/thread.lock">[thread.lock]</a>) and, although the WD doesn't quite say
so, as the template argument for <code>lock_guard</code> and <code>unique_lock</code>.
</p>

<p>
The requirements for a Mutex type include:
</p>

<ul>
<li>
<code>m.lock()</code> shall be well-formed and have [described] semantics, including a return type of <code>void</code>.
</li>
<li>
<code>m.try_lock()</code> shall be well-formed and have [described] semantics, including a return type of <code>bool</code>.
</li>
<li>
<code>m.unlock()</code> shall be well-formed and have [described] semantics, including a return type of <code>void</code>.
</li>
</ul>

<p>
Also, a Mutex type "shall not be copyable nor movable".
</p>

<p>
The latter requirement seems completely irrelevant, and the three
requirements on return types are tighter than they need to be. For
example, there's no reason that <code>lock_guard</code> can't be instantiated with a
type that's copyable. The rule is, in fact, that <code>lock_guard</code>, etc. won't
try to copy objects of that type. That's a constraint on locks, not on
mutexes. Similarly, the requirements for <code>void</code> return types are
unnecessary; the rule is, in fact, that <code>lock_guard</code>, etc. won't use any
returned value. And with the return type of <code>bool</code>, the requirement should
be that the return type is convertible to <code>bool</code>.
</p>

<p><i>[
Summit:
]</i></p>


<blockquote>
<p>
Move to open. Related to conceptualization and should probably be tackled as part of that.
</p>
<ul>
<li>
The intention is not only to place a constraint on what types such as
<code>lock_guard</code> may do with mutex types, but on what any code, including user
code, may do with mutex types. Thus the constraints as they are apply to
the mutex types themselves, not the current users of mutex types in the
standard.
</li>
<li>
This is a low priority issue; the wording as it is may be overly
restrictive but this may not be a real issue.
</li>
</ul>
</blockquote>

<p><i>[
Post Summit Anthony adds:
]</i></p>


<blockquote>
<p>
Section 32.6.4 <a href="https://wg21.link/thread.mutex.requirements">[thread.mutex.requirements]</a> conflates the
requirements on a generic Mutex type (including user-supplied mutexes)
with the requirements placed on the standard-supplied mutex types in an
attempt to group everything together and save space.
</p>
<p>
When applying concepts to chapter 30, I suggest that the concepts
<code>Lockable</code> and <code>TimedLockable</code> embody the requirements for
*use* of a mutex type as required by
<code>unique_lock/lock_guard/condition_variable_any</code>. These should be
relaxed as Pete describes in the issue. The existing words in 32.6.4 <a href="https://wg21.link/thread.mutex.requirements">[thread.mutex.requirements]</a> are requirements on all of
<code>std::mutex</code>, <code>std::timed_mutex</code>,
<code>std::recursive_mutex</code> and <code>std::recursive_timed_mutex</code>,
and should be rephrased as such.
</p>
</blockquote>

<p><i>[2017-03-01, Kona]</i></p>

<p>
SG1: Agreement that we need a paper.
</p>


<p id="res-936"><b>Proposed resolution:</b></p>
<p>
</p>





</body>
</html>
