[filesystem] thread safety on msvc 2010

Hi, I've been having some crashes in my code due to concurrent creation of boost::filesystem::path objects on several threads. The issue in short looks like function member static variable initialization is not thread safe in msvc 2010, but is in GCC. The main issue is with the construction of the std::locale and codecvt objects, I get crashes when some threads try to use a partially constructed instance of std::locale. I posted some details of my issue and possible fix at the end of bug 6320 https://svn.boost.org/trac/boost/ticket/6320, and would like to clean it up into a patch for consideration. Right now, I was looking at using boost::thread call_once to synchronize the std::locale and codecvt initialization code. I'm running locally with a boost::thread::call_once patch, and it seems to work for some simple test cases. I'd appreciate any thoughts, or pointers if anyone has worked on this issue, I saw some discussion at http://lists.boost.org/Archives/boost/2011/12/189183.php but it did not seem to move forwards. Thanks, Jacob Schloss

On Sun, Jan 27, 2013 at 7:50 PM, Jacob Schloss <jacob.schloss@urbanrobotics.net> wrote:
Hi,
I've been having some crashes in my code due to concurrent creation of boost::filesystem::path objects on several threads.
The issue in short looks like function member static variable initialization is not thread safe in msvc 2010, but is in GCC. The main issue is with the construction of the std::locale and codecvt objects, I get crashes when some threads try to use a partially constructed instance of std::locale.
I posted some details of my issue and possible fix at the end of bug 6320 https://svn.boost.org/trac/boost/ticket/6320, and would like to clean it up into a patch for consideration. Right now, I was looking at using boost::thread call_once to synchronize the std::locale and codecvt initialization code. I'm running locally with a boost::thread::call_once patch, and it seems to work for some simple test cases.
Some critical points to getting a patch accepted are that it applies only to the affected platform (i.e. Windows) and that it includes test cases that fail with the current code but pass with the patch applied. If it works for you with msvc 2010, I can test with other versions and compilers. Thanks, --Beman

[Jacob Schloss]
The issue in short looks like function member static variable initialization is not thread safe in msvc 2010
Correct. C++11 "magic statics" have not yet been implemented in VC, including VC 2012. (Nor does VC provide safety with locks.) Stephan T. Lavavej Visual C++ Libraries Developer
participants (3)
-
Beman Dawes
-
Jacob Schloss
-
Stephan T. Lavavej