-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Static initialization order problem of stdcat_mx_holder<>::mx_
#102
Comments
The constructor of |
Seems like a stupid problem that's surfacing now. This is suboptimal, but how about wrapping the Something along these lines: #if defined(_MSVC_STL_VERSION) && (_MSVC_STL_VERSION < 144)
template<class = void> std::mutex& stdcat_mx() noexcept
{
static std::mutex mx;
return mx;
}
#else
template<class = void> struct stdcat_mx_holder
{
static std::mutex mx_;
};
template<class T> std::mutex stdcat_mx_holder<T>::mx_;
inline std::mutex& stdcat_mx() noexcept
{
return stdcat_mx_holder<>::mx_;
}
#endif |
I suppose that's possible, yes. I had something different in mind - use This doesn't work for VS 2013, though, where I might need to apply your suggestion. (Or just mark the test as failed and pretend VS 2013 doesn't exist.) |
Oh, that's a neat trick too! I don't care about VS 2013, but I don't know about the boost policies. The question is how much all these legacy compilers are in use. vcpkg, for example, requires VC 2015 Update 3 as a minimal base C++14 compiler, which is problematic enough these days. In any case, I would use an inline/template method as an additional abstraction layer that returns a |
Should be fixed on develop now for msvc-12.0 as well, by 71ee26c. |
Unless you have something further to add, I consider this fixed. Thanks for the report. |
Thx Peter for your outstanding response! |
In commit #986efb142035 you switched to using a global static
std::mutex
when converting aboost::system:error_category
to astd::error_category
.This is subject to the static initialization order fiasco when a program sets up a static std::error_category variable based on a boost::system::error_category.
E.g. even this simple program leads to a crash with Visual C++ 17.4.3, because the compiler decides to initialize the static variable
ec1
beforeboost::system::detail::stdcat_mx_holder<>::mx_
, andboost::system::error_category::init_stdcat()
locks an uninitialized mutex:Callstack:
The text was updated successfully, but these errors were encountered: