<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1159: Unclear spec for resource_deadlock_would_occur</title>
<meta property="og:title" content="Issue 1159: Unclear spec for resource_deadlock_would_occur">
<meta property="og:description" content="C++ library issue. Status: C++11">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1159.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#C++11">C++11</a> status.</em></p>
<h3 id="1159"><a href="lwg-defects.html#1159">1159</a>. Unclear spec for <code>resource_deadlock_would_occur</code></h3>
<p><b>Section:</b> 32.6.5.4.3 <a href="https://wg21.link/thread.lock.unique.locking">[thread.lock.unique.locking]</a> <b>Status:</b> <a href="lwg-active.html#C++11">C++11</a>
 <b>Submitter:</b> LWG <b>Opened:</b> 2009-06-28 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#thread.lock.unique.locking">issues</a> in [thread.lock.unique.locking].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++11">C++11</a> status.</p>
<p><b>Duplicate of:</b> <a href="lwg-closed.html#1219" title="unique_lock::lock and resource_deadlock_would_occur (Status: Dup)">1219</a></p>
<p><b>Discussion:</b></p>

<p><b>Addresses UK 327, UK 328</b></p>

<p><b>UK 327 Description</b></p>
        <p>Not clear what
        the specification for error condition
        <code>resource_deadlock_would_occur</code> means. It is perfectly
        possible for this thread to own the mutex without setting
        owns to true on this specific lock object. It is also
        possible for lock operations to succeed even if the thread
        does own the mutex, if the mutex is recursive. Likewise, if
        the mutex is not recursive and the mutex has been locked
        externally, it is not always possible to know that this
        error condition should be raised, depending on the host
        operating system facilities. It is possible that 'i.e.' was
        supposed to be 'e.g.' and that suggests that recursive
        locks are not allowed. That makes sense, as the
        exposition-only member owns is boolean and not a integer to
        count recursive locks.</p>
        
<p><b>UK 327 Suggestion</b></p>
        <p>Add a precondition <code>!owns</code>. Change the 'i.e.'
        in the error condition to be 'e.g.' to allow for this
        condition to propogate deadlock detection by the host OS.</p>
<p><b>UK 327 Notes</b></p>
<p>Create an issue. Assigned to Lawrence Crowl. Note: not sure what try_lock 
    means for recursive locks when you are the owner. POSIX has language on 
    this, which should ideally be followed. Proposed fix is not quite right, for 
    example, try_lock should have different wording from lock.</p>

<p><b>UK 328 Description</b></p>

        <p>There is a missing precondition that <code>owns</code>
        is true, or an <code>if(owns)</code> test is missing from the effect
        clause</p>
<p><b>UK 328 Suggestion</b></p>
        <p>Add a
        precondition that <code>owns == true</code>. Add an error condition to
        detect a violation, rather than yield undefined behaviour.</p>
<p><b>UK 328 Notes</b></p>
<p>Handle in same issue as UK 327. Also uncertain that the proposed resolution 
    is the correct one.</p>

<p><i>[
2009-11-11 Alisdair notes that this issue is very closely related to <a href="lwg-closed.html#1219" title="unique_lock::lock and resource_deadlock_would_occur (Status: Dup)">1219</a><sup><a href="https://cplusplus.github.io/LWG/issue1219" title="Latest snapshot">(i)</a></sup>,
if not a dup.
]</i></p>


<p><i>[
2010-02-12 Anthony provided wording.
]</i></p>


<p><i>[
2010 Pittsburgh:
]</i></p>


<blockquote><p>
Wording updated and moved to Ready for Pittsburgh.
</p></blockquote>



<p id="res-1159"><b>Proposed resolution:</b></p>
<p>
Modify 32.6.5.4.3 <a href="https://wg21.link/thread.lock.unique.locking">[thread.lock.unique.locking]</a> p3 to say:
</p>

<blockquote>
<pre>void lock();</pre>
<blockquote>
<p>...</p>
<p>
3 <i>Throws:</i> <ins>Any exception thrown by <code>pm-&gt;lock()</code>.
<code>std::system_error</code> if an exception is required (32.2.2 <a href="https://wg21.link/thread.req.exception">[thread.req.exception]</a>).
<code>std::system_error</code> with an error condition of
<code>operation_not_permitted</code> if <code>pm</code> is <code>0</code>.
<code>std::system_error</code> with an error condition of
<code>resource_deadlock_would_occur</code> if on entry <code>owns</code> is <code>true</code>.</ins>
<del><code>std::system_error</code> when the
postcondition cannot be achieved.</del>
</p>
</blockquote>
</blockquote>

<p>
Remove 32.6.5.4.3 <a href="https://wg21.link/thread.lock.unique.locking">[thread.lock.unique.locking]</a> p4 (Error condition clause).
</p>

<p>
Modify 32.6.5.4.3 <a href="https://wg21.link/thread.lock.unique.locking">[thread.lock.unique.locking]</a> p8 to say:
</p>

<blockquote>
<pre>bool try_lock();</pre>
<blockquote>
<p>...</p>
<p>
8 <i>Throws:</i> <ins>Any exception thrown by <code>pm-&gt;try_lock()</code>.
<code>std::system_error</code> if an exception is required (32.2.2 <a href="https://wg21.link/thread.req.exception">[thread.req.exception]</a>).
<code>std::system_error</code> with an error condition of
<code>operation_not_permitted</code> if <code>pm</code> is <code>0</code>.
<code>std::system_error</code> with an error condition of
<code>resource_deadlock_would_occur</code> if on entry <code>owns</code> is <code>true</code>.</ins>
<del><code>std::system_error</code> when the
postcondition cannot be achieved.</del>
</p>
</blockquote>
</blockquote>

<p>
Remove 32.6.5.4.3 <a href="https://wg21.link/thread.lock.unique.locking">[thread.lock.unique.locking]</a> p9 (Error condition clause).
</p>

<p>
Modify 32.6.5.4.3 <a href="https://wg21.link/thread.lock.unique.locking">[thread.lock.unique.locking]</a> p13 to say:
</p>

<blockquote>
<pre>template &lt;class Clock, class Duration&gt;
  bool try_lock_until(const chrono::time_point&lt;Clock, Duration&gt;&amp; abs_time);</pre>
<blockquote>
<p>...</p>
<p>
13 <i>Throws:</i> <ins>Any exception thrown by <code>pm-&gt;try_lock_until()</code>.
<code>std::system_error</code> if an exception is required (32.2.2 <a href="https://wg21.link/thread.req.exception">[thread.req.exception]</a>).
<code>std::system_error</code> with an error condition of
<code>operation_not_permitted</code> if <code>pm</code> is <code>0</code>.
<code>std::system_error</code> with an error condition of
<code>resource_deadlock_would_occur</code> if on entry <code>owns</code> is <code>true</code>.</ins>
<del><code>std::system_error</code> when the
postcondition cannot be achieved.</del>
</p>
</blockquote>
</blockquote>

<p>
Remove 32.6.5.4.3 <a href="https://wg21.link/thread.lock.unique.locking">[thread.lock.unique.locking]</a> p14 (Error condition clause).
</p>

<p>
Modify 32.6.5.4.3 <a href="https://wg21.link/thread.lock.unique.locking">[thread.lock.unique.locking]</a> p18 to say:
</p>

<blockquote>
<pre>template &lt;class Rep, class Period&gt;
  bool try_lock_for(const chrono::duration&lt;Rep, Period&gt;&amp; rel_time);</pre>
<blockquote>
<p>...</p>
<p>
18 <i>Throws:</i> <ins>Any exception thrown by <code>pm-&gt;try_lock_for()</code>.
<code>std::system_error</code> if an exception is required (32.2.2 <a href="https://wg21.link/thread.req.exception">[thread.req.exception]</a>).
<code>std::system_error</code> with an error condition of
<code>operation_not_permitted</code> if <code>pm</code> is <code>0</code>.
<code>std::system_error</code> with an error condition of
<code>resource_deadlock_would_occur</code> if on entry <code>owns</code> is <code>true</code>.</ins>
<del><code>std::system_error</code> when the
postcondition cannot be achieved.</del>
</p>
</blockquote>
</blockquote>

<p>
Remove 32.6.5.4.3 <a href="https://wg21.link/thread.lock.unique.locking">[thread.lock.unique.locking]</a> p19 (Error condition clause).
</p>






</body>
</html>
