Boost C++ Libraries: Ticket #1850: request for unlock_guard (and/or unique_unlock) to compliment lock_guard/unique_lock https://svn.boost.org/trac10/ticket/1850 <p> I'd like to request an unlock_guard class template to complement lock_guard. I wonder if it is any more involved than the attached patch. A unique_unlock class template may be nice as well, but an unlock_guard seems sufficient. </p> <p> Is there a known reason it was left out of the proposal for the C++0x thread library, or is it a simple oversight? I don't see any reference to it in the documents. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1850 Trac 1.4.3 bgreen0@… Tue, 22 Apr 2008 23:20:03 GMT attachment set https://svn.boost.org/trac10/ticket/1850 https://svn.boost.org/trac10/ticket/1850 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">lock.patch</span> </li> </ul> <p> patch adding unlock_guard to boost/thread/locks.hpp </p> Ticket viboes Fri, 20 Nov 2009 12:39:37 GMT <link>https://svn.boost.org/trac10/ticket/1850#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1850#comment:1</guid> <description> <p> The following prototype seems not clear to me </p> <pre class="wiki">70 unlock_guard(Mutex&amp; m_,adopt_lock_t): 71 m(m_) 72 {} </pre><p> For lock and unique lock adopt_lock_t parameter means adoption of the mutex was lock. For unlock_guard, adopt_lock_t will mean adoption of the mutex was unlock? </p> <p> I would prefer a new structure </p> <pre class="wiki">struct adopt_unlock_t {} const adopt_unlock_t adopt_unlock={}; unlock_guard(Mutex&amp; m_,adopt_unlock_t): m(m_) {} </pre><p> Maybe is just an english language question I don't master. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 27 Nov 2010 09:35:26 GMT</pubDate> <title>type, severity changed https://svn.boost.org/trac10/ticket/1850#comment:2 https://svn.boost.org/trac10/ticket/1850#comment:2 <ul> <li><strong>type</strong> <span class="trac-field-old">Patches</span> → <span class="trac-field-new">Feature Requests</span> </li> <li><strong>severity</strong> <span class="trac-field-old">Problem</span> → <span class="trac-field-new">Not Applicable</span> </li> </ul> <p> As this patch doesn't provides test and documentation I think we can downgrade it to Feature Request. Please could you provide them? </p> Ticket viboes Thu, 05 Jan 2012 05:48:52 GMT owner, status changed https://svn.boost.org/trac10/ticket/1850#comment:3 https://svn.boost.org/trac10/ticket/1850#comment:3 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Anthony Williams</span> to <span class="trac-author">viboes</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket viboes Wed, 21 Mar 2012 20:52:21 GMT <link>https://svn.boost.org/trac10/ticket/1850#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1850#comment:4</guid> <description> <p> I'm wondering if this features is not dangerous combined with other lock guards. E.g. The user of lock_guard expects his lock to be locked during his lifetime, so nesting a unlock_guard will break the user expectations. I think that as far as we unlock we are transferring ownership, so the safe way to nest the unlock guard is to use move semantics from a lock owning the mutex. What do you think of a reverse_lock </p> <pre class="wiki"> template&lt;typename Lock&gt; class reverse_lock { private: Lock&amp; m; public: reverse_lock(reverse_lock const&amp;) = delete; reverse_lock&amp; operator=(reverse_lock const&amp;) = delete; typedef typename Lock::mutex_type mutex_type; explicit reverse_lock(Lock&amp; m_): m(m_) { BOOST_ASSERT(m.owns_lock()); m.unlock(); } reverse_lock(Lock&amp; m_,adopt_unlock_t): m(m_) { BOOST_ASSERT(!m.owns_lock()); } ~reverse_lock() { if(!m.owns_lock()) m.lock(); } explicit operator bool() const BOOST_NOEXCEPT { return m.owns_lock(); // always false } bool owns_lock() const BOOST_NOEXCEPT { return m.owns_lock(); // always false } mutex_type* mutex() const BOOST_NOEXCEPT { return m.mutex(); } mutex_type* release() BOOST_NOEXCEPT { return m.release(); } }; </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 31 Mar 2012 08:36:50 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/1850 https://svn.boost.org/trac10/ticket/1850 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">1850.patch</span> </li> </ul> Ticket viboes Sat, 31 Mar 2012 08:38:42 GMT <link>https://svn.boost.org/trac10/ticket/1850#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1850#comment:5</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/1850#comment:4" title="Comment 4">viboes</a>: </p> <blockquote class="citation"> <p> I'm wondering if this features is not dangerous combined with other lock guards. E.g. The user of lock_guard expects his lock to be locked during his lifetime, so nesting a unlock_guard will break the user expectations. I think that as far as we unlock we are transferring ownership, so the safe way to nest the unlock guard is to use move semantics from a lock owning the mutex. What do you think of a reverse_lock </p> <pre class="wiki"> template&lt;typename Lock&gt; class reverse_lock { private: Lock&amp; m; public: reverse_lock(reverse_lock const&amp;) = delete; reverse_lock&amp; operator=(reverse_lock const&amp;) = delete; typedef typename Lock::mutex_type mutex_type; explicit reverse_lock(Lock&amp; m_): m(m_) { BOOST_ASSERT(m.owns_lock()); m.unlock(); } reverse_lock(Lock&amp; m_,adopt_unlock_t): m(m_) { BOOST_ASSERT(!m.owns_lock()); } ~reverse_lock() { if(!m.owns_lock()) m.lock(); } explicit operator bool() const BOOST_NOEXCEPT { return m.owns_lock(); // always false } bool owns_lock() const BOOST_NOEXCEPT { return m.owns_lock(); // always false } mutex_type* mutex() const BOOST_NOEXCEPT { return m.mutex(); } mutex_type* release() BOOST_NOEXCEPT { return m.release(); } }; </pre></blockquote> <p> I have removed all the member operations as the goal is to ensure that the mutex is lock after destructor. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 31 Mar 2012 15:24:37 GMT</pubDate> <title>milestone changed https://svn.boost.org/trac10/ticket/1850#comment:6 https://svn.boost.org/trac10/ticket/1850#comment:6 <ul> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.36.0</span> → <span class="trac-field-new">Boost 1.50.0</span> </li> </ul> <p> Committed in trunk revision 77662. </p> Ticket viboes Mon, 28 May 2012 15:07:58 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/1850#comment:7 https://svn.boost.org/trac10/ticket/1850#comment:7 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Committed in release branch at <a class="changeset" href="https://svn.boost.org/trac10/changeset/78543" title="Merged boost.thread from trunk">[78543]</a> </p> Ticket