From 1d845408dd1bb50208bf20f03c0459f76c2444d3 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 25 Apr 2019 01:01:48 +0300 Subject: [PATCH] Fix thread safety issue in std interop --- include/boost/system/detail/config.hpp | 5 +++++ include/boost/system/detail/std_interoperability.hpp | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/include/boost/system/detail/config.hpp b/include/boost/system/detail/config.hpp index 2ad8201..ab1f304 100644 --- a/include/boost/system/detail/config.hpp +++ b/include/boost/system/detail/config.hpp @@ -22,6 +22,11 @@ # undef BOOST_SYSTEM_HAS_SYSTEM_ERROR #endif +#if defined(BOOST_NO_CXX11_HDR_MUTEX) +// Required for thread-safe map manipulation +# undef BOOST_SYSTEM_HAS_SYSTEM_ERROR +#endif + // BOOST_SYSTEM_NOEXCEPT // Retained for backward compatibility diff --git a/include/boost/system/detail/std_interoperability.hpp b/include/boost/system/detail/std_interoperability.hpp index f52e99e..a6ec728 100644 --- a/include/boost/system/detail/std_interoperability.hpp +++ b/include/boost/system/detail/std_interoperability.hpp @@ -10,6 +10,7 @@ #include #include #include +#include // @@ -92,6 +93,9 @@ inline std::error_category const & to_std_category( boost::system::error_categor typedef std::map< boost::system::error_category const *, std::unique_ptr, cat_ptr_less > map_type; static map_type map_; + static std::mutex map_mx_; + + std::lock_guard guard( map_mx_ ); map_type::iterator i = map_.find( &cat );