Calling std::locale::global() in one thread can lead to crashes in another thread which uses iostreams (e.g. creates an ifstream).The problem seems to be that the std::locale()-Constructor first stores a pointer to the global locale through _Getgloballocale and then increases the reference count on the global locale through another call to _Getgloballocale: locale() _THROW0() : _Ptr(_Init()) { // construct from current locale _Getgloballocale()->_Incref(); }Between these two calls, a call of std::locale::global() can change the global locale, so that the ref count of the wrong object is increased and the _Ptr object could become invalid.There are some shell extensions which call std::locale::global so with enough bad luck, it is called when a file open dialog is created without any opportunity for us to prevent it. In effect, this means that we can't use iostreams in background threads at the same time as file open dialogs are used.
Visual Studio/Team Foundation Server/.NET Framework Tooling version
Steps to reproduce
Product Language
Operating System
Operating System Language
Actual results
Expected results