title: Concurrency memory corruption using Boost 1.55 Thread and Filesystem (Visual Studio 2013)
body: <p>I have the following code:</p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;thread&gt;
  
  #define BOOST_THREAD_DYN_LINK
  #include "boost/filesystem.hpp"
  #include "boost/thread/thread.hpp"
  
  using namespace std;
  
  void testEx(std::string &amp; name){
      while (1){
          boost::filesystem::path perc(name);
          if (boost::filesystem::exists(perc))
              cout &lt;&lt; "yes" &lt;&lt; endl;
      }
  }
  
  int main(){
      std::string name = "c:\\text.txt";
      vector&lt;boost::thread&gt; pool;
      for (int i = 0; i &lt; 10;i++)
          pool.emplace_back(testEx, name);
  
      while (1){
          std::ofstream out(name, std::ios_base::out | std::ios_base::app);
          out &lt;&lt; "a" &lt;&lt; std::endl;
          out.close();
      }
      for (auto &amp; t : pool)
          t.join();
  }
  </code></pre>
  
  <p>The main thread is writing a file. With child threads i check if the file exists. The program often crashes with memory corruption in the line where i create a boost::filesystem::path instance.</p>
  
  <p>If i use std::thread instead of boost::thread the program works fine.</p>
  
  <p>Is there anything i can do to get this program work with boost::thread (lots of legacy code). Why is this happening?</p>