Re: [Boost-bugs] [Boost C++ Libraries] #12620: Make boost::unique_lock::unlock respect BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #12620: Make boost::unique_lock::unlock respect BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-12-30 01:39:04


#12620: Make boost::unique_lock::unlock respect
BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED
-------------------------------------------------+-------------------------
  Reporter: Alexandre Pereira Nunes | Owner: viboes
  <alexandre.nunes@…> | Status: new
      Type: Bugs | Component: thread
 Milestone: To Be Determined | Severity: Problem
   Version: Boost 1.62.0 | Keywords:
Resolution: |
-------------------------------------------------+-------------------------
Changes (by viboes):

 * owner: anthonyw => viboes


Old description:

> For a C++11 conformant g++ with working C++11 threads, the following code
> works if LIB is defined to std and throws if defined to boost::
>
> #define LIB boost
>
> LIB::mutex mtx;
> LIB::unique_lock<LIB::mutex> l(mtx, LIB::defer_lock);
> LIB::condition_variable cnd;
> cnd.wait(l, []{ /*whatever*/ return true;}); // this throws.
>
> The attached patch makes boost::unique_lock::unlock respect
> BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED and not require the lock
> to be held (if you'll ever have only one thread waiting on a condition
> variable it seems that the mutex is useless as there's no race involved,
> c++11 threads at least when backed by pthread seems to follow that
> behavior).
>
> Even with this patch, boost *will* lock the mutex on exit - I didn't
> attempt to change that (as my code copes with that), but c++11 seems to
> avoid touching the mutex or correctly leaves it as it once was.
>
> I'm not sure what/if any of this behavior is standardized or
> implementation dependent, but it seems more coherent to respect
> BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED - specially the common
> case where it's not defined.

New description:

 For a C++11 conformant g++ with working C++11 threads, the following code
 works if LIB is defined to std and throws if defined to boost::


 {{{
 #define LIB boost

 LIB::mutex mtx;
 LIB::unique_lock<LIB::mutex> l(mtx, LIB::defer_lock);
 LIB::condition_variable cnd;
 cnd.wait(l, []{ /*whatever*/ return true;}); // this throws.

 }}}

 The attached patch makes boost::unique_lock::unlock respect
 BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED and not require the lock
 to be held (if you'll ever have only one thread waiting on a condition
 variable it seems that the mutex is useless as there's no race involved,
 c++11 threads at least when backed by pthread seems to follow that
 behavior).

 Even with this patch, boost *will* lock the mutex on exit - I didn't
 attempt to change that (as my code copes with that), but c++11 seems to
 avoid touching the mutex or correctly leaves it as it once was.

 I'm not sure what/if any of this behavior is standardized or
 implementation dependent, but it seems more coherent to respect
 BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED - specially the common
 case where it's not defined.

--
-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/12620#comment:1>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC