id summary reporter owner description type status milestone component version severity resolution keywords cc 12386 lock_error exception when using try_lock_for() on Windows Franz Beaune viboes "The following program immediately crashes with a lock_error exception on Windows: {{{ #include #include #include using namespace boost; shared_mutex mtx; void f() { while (true) { unique_lock lock(mtx, defer_lock); while (!lock.try_lock_for(chrono::milliseconds(1))) {} } } void g() { while (true) { shared_lock lock(mtx, defer_lock); while (!lock.try_lock_for(chrono::milliseconds(1))) {} } } int main() { const int N = 12; thread* threads[N]; for (int i = 0; i < N; ++i) threads[i] = new thread(i % 2 ? f : g); for (int i = 0; i < N; ++i) threads[i]->join(); return 0; } }}} Callstack when the lock_error exception is thrown: {{{ test.exe!boost::throw_exception(const boost::lock_error & e) test.exe!boost::shared_mutex::try_lock_until(const boost::chrono::time_point > > & tp) test.exe!boost::shared_mutex::try_lock_until > >(const boost::chrono::time_point > > & t) test.exe!boost::shared_mutex::try_lock_for<__int64,boost::ratio<1,1000> >(const boost::chrono::duration<__int64,boost::ratio<1,1000> > & rel_time) test.exe!boost::unique_lock::try_lock_for<__int64,boost::ratio<1,1000> >(const boost::chrono::duration<__int64,boost::ratio<1,1000> > & rel_time) }}} Boost.Thread code that throws the exception, in boost\thread\win32\shared_mutex.hpp: {{{ bool try_lock_until(const chrono::time_point& tp) { for(;;) { state_data old_state=state; for(;;) { state_data new_state=old_state; if(new_state.shared_count || new_state.exclusive) { ++new_state.exclusive_waiting; if(!new_state.exclusive_waiting) { boost::throw_exception(boost::lock_error()); // <-- HERE } new_state.exclusive_waiting_blocked=true; } else { new_state.exclusive=true; } ... }}} Tested with Boost 1.55 and Boost 1.61, both compiled with Visual Studio 2013 in x64 mode, on Windows 10 64-bit." Bugs closed To Be Determined thread Boost 1.61.0 Showstopper duplicate lock_error