Boost C++ Libraries: Ticket #10715: Race condition in codecvt() persists in VC++ https://svn.boost.org/trac10/ticket/10715 <p> This is a restatement of Ticket <a class="reopened ticket" href="https://svn.boost.org/trac10/ticket/6320" title="#6320: Bugs: race condition in boost::filesystem::path leads to crash when used in ... (reopened)">#6320</a>, which is still causing me problems; specifically when path objects are used in a DLL with multithreading. Environment is VC++11, although I believe it is also applicable to VC++12. Both versions have documentation warnings against using static local variables in a multithreaded application. </p> <p> Demo code: A DLL containing the simple function: </p> <pre class="wiki">// exported function. extern "C" DLL_API void fnDll( void ) { boost::filesystem::path p("test_path"); return; } </pre><p> The main program creates threads to load the DLL and call this function: </p> <pre class="wiki">void thread_func() { boost::this_thread::sleep(boost::posix_time::milliseconds(100)); HINSTANCE hLib = LoadLibraryA("Dll.dll"); if (hLib != NULL) { // Resolve test function in DLL FARPROC f = GetProcAddress(hLib,"fnDll"); if (f) f(); // call it } } int main(int argc, _TCHAR* argv[]) { boost::thread_group tg; for(int i = 0; i &lt; 2; i++) tg.create_thread(thread_func); tg.join_all(); return 0; } </pre><p> Built and run for debug, this code fails when the BOOST_ASSERT: </p> <p> "codecvt_facet_ptr() facet hasn't been properly initialized" </p> <p> fires on line 888, in const path::codecvt_type&amp; path::codecvt() </p> <p> The user workaround is to put code in <a class="missing wiki">DllMain</a>'s DLL_PROCESS_ATTACH, as described in the earlier ticket, to force initialisation before multiple threads share the DLL. </p> <p> I attach the Visual Studio project used to test this. This DLL scenario is a simplification of a genuine situation: I found it when an Apache add-on started crashing its host. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10715 Trac 1.4.3 willw@… Wed, 29 Oct 2014 15:52:42 GMT attachment set https://svn.boost.org/trac10/ticket/10715 https://svn.boost.org/trac10/ticket/10715 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">Boost FileSystem Test.zip</span> </li> </ul> <p> Visual Studio 2012 project demo's multi-threaded ASSERT </p> Ticket raad@… Mon, 27 Jun 2016 13:45:50 GMT cc set https://svn.boost.org/trac10/ticket/10715#comment:1 https://svn.boost.org/trac10/ticket/10715#comment:1 <ul> <li><strong>cc</strong> <span class="trac-author">raad@…</span> added </li> </ul> Ticket