Opened 6 years ago
Closed 6 years ago
#12620 closed Support Requests (worksforme)
Make boost::unique_lock::unlock respect BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED
Reported by: | Owned by: | viboes | |
---|---|---|---|
Milestone: | To Be Determined | Component: | thread |
Version: | Boost 1.62.0 | Severity: | Not Applicable |
Keywords: | Cc: |
Description (last modified by )
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.
Attachments (1)
Change History (4)
by , 6 years ago
Attachment: | lock_types.patch added |
---|
comment:1 by , 6 years ago
Description: | modified (diff) |
---|---|
Owner: | changed from | to
comment:2 by , 6 years ago
Severity: | Problem → Not Applicable |
---|---|
Type: | Bugs → Support Requests |
comment:3 by , 6 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
The implementation corresponds to the documentation and I believe to the standard library as well (http://en.cppreference.com/w/cpp/thread/unique_lock/unlock).