Re: [Boost-bugs] [Boost C++ Libraries] #6320: race condition in boost::filesystem::path leads to crash when used in multithreaded programs

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #6320: race condition in boost::filesystem::path leads to crash when used in multithreaded programs
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2017-05-09 15:07:24


#6320: race condition in boost::filesystem::path leads to crash when used in
multithreaded programs
-------------------------------+-------------------------
  Reporter: aris.basic@… | Owner: bemandawes
      Type: Bugs | Status: reopened
 Milestone: To Be Determined | Component: filesystem
   Version: Boost 1.62.0 | Severity: Showstopper
Resolution: | Keywords:
-------------------------------+-------------------------

Comment (by anonymous):

 Replying to [comment:24 stl]:
> Replying to [comment:23 stl]:
> > Some simplified code to reproduce the crash. As concurrency bugs are
 timing dependent, this will crash most of the time, but not always.
> >
> > {{{
> > #include <boost/filesystem.hpp>
> > #include <boost/thread.hpp>
> >
> > void thr()
> > {
> > boost::filesystem::path file(L"C:\\test");
> > boost::this_thread::sleep(boost::posix_time::milliseconds(10));
> > std::cout << file.string() << std::endl;
> > }
> >
> >
> > int main()
> > {
> > boost::thread_group tg;
> > for (size_t n = 0; n < 5; ++n)
> > {
> > tg.create_thread(thr);
> > }
> > tg.join_all();
> > return 0;
> > }
> >
> > }}}
>
> Of course, this code is meant to reproduce the crash on Windows, where
 boost::filesystem::path uses wide characters natively, and thus must
 convert when using string().

 {{{boost::barrier}}} can help a lot to catch threading issues:

 {{{
 const int num = 10;
 boost::barrier b(num + 1);
 std::vector<std::thread> threads;
 for (int i = 0; i < num; ++i)
         threads.emplace_back([&b] { b.wait();
 boost::filesystem::path::codecvt(); });

 b.wait();

 for (auto& thread: threads)
         thread.join();
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/6320#comment:26>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-05-09 15:11:12 UTC