Boost logo

Boost Users :

Subject: Re: [Boost-users] filesystem::path threadsafe ?? (1.48) Options
From: Wolfgang Fertsak (wolfgang.fertsak_at_[hidden])
Date: 2011-12-27 07:49:15


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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net