Re: [Boost-users] filesystem::path threadsafe ?? (1.48) Options
Here is the sample code that crashes every time i compile project as multibyte and not unicode and ahve user wchar_t as default type #include <boost/thread.hpp> #include <boost/filesystem.hpp> int main(void) { std::string sPath("c:\\Development"); boost::thread_group tg; for(int i = 0; i < 10; i++) { tg.create_thread([&sPath](){ boost::this_thread::sleep(boost::posix_time::milliseconds(10)); boost::filesystem::path p(sPath); boost::filesystem::directory_iterator di(p), end; while(di != end) std::cout << (*di).path().string() << std::endl; }); } tg.join_all(); }
On 23.12.2011 16:45, Aris Basic wrote:
Here is the sample code that crashes every time
Hi, your sample code also crashes on my machine (VS 2005 SP1, boost 1.48) (BTW the directory_iterator di doesn't get incremented in your sample, which results in an endless-loop, but the program crashes before that anyway) I think the problem is in file filesystem/v3/source/path.cpp in method const path::codecvt_type *& path::wchar_t_codecvt_facet() { static const std::codecvt<wchar_t, char, std::mbstate_t> * facet( &std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t> > (path_locale())); return facet; } This method is entered by multiple threads concurrently and the static pointer "facet" gets initialized by the first thread (which takes some time) but the other threads don't wait and just continue while facet is a NULL pointer. In boost 1.44 this crash didn't occur. It seems that the initialization of global variable const fs::path dot_path(L"."); in filesystem/v3/source/path.cpp resulted in a call of path::wchar_t_codecvt_facet(), so the static "facet" pointer got initialized during program startup while no other threads were running. In boost 1.48 the initialization of the same globale variable doesn't result in a call of path::wchar_t_codecvt_facet() so race conditions might occur during initialization of the static "facet" pointer (in C++ 03). Regards, Wolfgang
On 23.12.2011 16:45, Aris Basic wrote:
Here is the sample code that crashes every time
I think the problem is in file filesystem/v3/source/path.cpp in method
const path::codecvt_type *& path::wchar_t_codecvt_facet() { static const std::codecvt<wchar_t, char, std::mbstate_t> * facet( &std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t> > (path_locale())); return facet; }
This method is entered by multiple threads concurrently and the static pointer "facet" gets initialized by the first thread (which takes some time) but the other threads don't wait and just continue while facet is a NULL pointer. That's great detective work, Wolfgang. Please file a Trac ticket with
On 12/27/2011 06:49 AM, Wolfgang Fertsak wrote: this information so that the maintainers can get this fixed. This seems like a serious regression. Rob
On 27.12.2011 16:46, Rob Riggs wrote:
That's great detective work, Wolfgang. Please file a Trac ticket with this information so that the maintainers can get this fixed. This seems like a serious regression.
Thank you ;-) I noticed Aris already filed a ticket(https://svn.boost.org/trac/boost/ticket/6320), I simply added my analysis as a comment. Wolfgang
participants (3)
-
Aris Basic
-
Rob Riggs
-
Wolfgang Fertsak