Opened 7 years ago
Last modified 6 years ago
#11499 assigned Bugs
windows - exception lock_error while intensive locking/unlocking of shared_mutex on many threads
Reported by: | Owned by: | viboes | |
---|---|---|---|
Milestone: | To Be Determined | Component: | thread |
Version: | Boost 1.59.0 | Severity: | Problem |
Keywords: | Cc: |
Description
#include "stdafx.h" #include <boost/thread/shared_mutex.hpp> #include <thread> #include <mutex> #include <shared_mutex> #include <atomic> #include <vector> using MutexT = boost::shared_mutex; using ReaderLockT = std::lock_guard<MutexT>; using WriterLockT = std::shared_lock<MutexT>; MutexT gMutex; std::atomic<bool> running = true; long reads = 0; void read() { while (running) { ReaderLockT lock(gMutex); std::this_thread::yield(); ++reads; } } int main() { using namespace std; vector<thread> threads; for (int i = 0; i < 256; ++i) { threads.emplace_back(thread(read)); } string str; getline(std::cin, str); running = false; for (auto& thread : threads) { thread.join(); } return 0; }
Attachments (1)
Change History (14)
comment:1 by , 7 years ago
Version: | Boost 1.57.0 → Boost 1.58.0 |
---|
comment:2 by , 7 years ago
Version: | Boost 1.58.0 → Boost 1.59.0 |
---|
comment:3 by , 7 years ago
Component: | None → thread |
---|---|
Owner: | set to |
comment:4 by , 7 years ago
comment:5 by , 7 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:6 by , 7 years ago
I'm unable to reproduce it on a MAC (I don't have a Windows machine available). Please, could you give more information?
by , 7 years ago
Attachment: | shared_mutex_exception.png added |
---|
comment:8 by , 7 years ago
In shared_mutex.hpp @393 lock() member function
void lock() {
#if defined BOOST_THREAD_USES_DATETIME
BOOST_VERIFY(timed_lock(::boost::detail::get_system_time_sentinel()));
#else
BOOST_VERIFY(try_lock_until(chrono::steady_clock::now()));
#endif
}
comment:9 by , 7 years ago
Please, could you try using a version >= 0
#define BOOST_THREAD_VERSION 4 #include <boost/thread/shared_mutex.hpp> ....
If you can not, could you try replacing
#if defined BOOST_THREAD_USES_DATETIME BOOST_VERIFY(timed_lock(::boost::detail::get_system_time_sentinel())); #else BOOST_VERIFY(try_lock_until(chrono::steady_clock::now())); #endif
by
BOOST_VERIFY(try_lock_until(chrono::steady_clock::now()));
The same for lock_shared.
Thanks for your help, Vicente
comment:10 by , 7 years ago
comment:12 by , 7 years ago
Summary: | exception lock_error while intensive locking/unlocking of shared_mutex on many threads → windows - exception lock_error while intensive locking/unlocking of shared_mutex on many threads |
---|
comment:13 by , 6 years ago
You can define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN to get the generic implementation. It is slower but IMHO it has less bugs.
See #12386
Replying to andrew maclean <agm@…>: