title: Boost - When interrupting thread, access violation occurs
body: <p>I have some code, that started in boost::thread. That thread is interrupted in some moment.</p>
  
  <p>Thread code:</p>
  
  <pre><code>void CLifeSimLauncherDlg::hashFilesThread() {
      wstring *pathToMainDir = new wstring(L"./LifeSimGame");
  
      boost::this_thread::interruption_point();
  
      MyLib::hashFilesInDirExternal(doc, pathToMainDir,
          cpr);
  }
  </code></pre>
  
  <p>Function <code>hashFilesInDirExternal</code> calling another function <code>hashFilesInDir</code></p>
  
  <pre><code>void FileIO::hashFilesInDir(wstring dirn, pugi::xml_node *root,
      void(*calcHashFunction)(wstring, wstring, uintmax_t, pugi::xml_node*))
  {
      try {
          long long int folderSize = 0;
          boost::replace_all(dirn, "\\\\", "\\");
          boost::replace_all(dirn, "\\", "/");
          boost::filesystem::path folderPath(dirn);
          if (boost::filesystem::exists(folderPath)) {
              boost::filesystem::directory_iterator end_itr;
  
              for (boost::filesystem::directory_iterator dirIte(dirn); dirIte != end_itr; ++dirIte)
              {
                  boost::filesystem::path filePath(dirIte-&gt;path());
                  try {
                      if (boost::filesystem::is_directory(dirIte-&gt;status()))
                      {
  
                          hashFilesInDir(MyStrings::StringToWString(dirIte-&gt;path().string()), root, calcHashFunction);
                      }
                      else {
                          try {
                              (*calcHashFunction)(
                                  MyStrings::StringToWString(dirIte-&gt;path().string()),
                                  MyStrings::StringToWString(to_string(boost::filesystem::file_size(dirIte-&gt;path()))),
                                  boost::filesystem::file_size(dirIte-&gt;path()),
                                  root
                                  );
                          }
                          catch (exception ex) {
                              MessageBox(nullptr, L"Some error occured on file hashing2.", L"Error:", MB_OK);
                          }
                      }
                  }
                  catch (exception&amp; e) {
                      cout &lt;&lt; e.what() &lt;&lt; endl;
                  }
              }
  
          }
      }
      catch (...) {
          MessageBox(nullptr, L"Some error occured on file indexing.", L"Error:", MB_OK);
      }
  
  }
  </code></pre>
  
  <p>When thread interrupted, program fails with Access Violation Exception:</p>
  
  <pre><code>Exception thrown at 0x005B3A1C in LifeSimLauncher.Main.exe: 0xC0000005: Access violation executing location 0x005B3A1C.
  </code></pre>
  
  <p>at path.hpp, line 412, that contains code</p>
  
  <pre><code>path_traits::convert(&amp;*m_pathname.begin(), &amp;*m_pathname.begin()+m_pathname.size(),
          tmp);
  </code></pre>
  
  <p>this code is in the </p>
  
  <pre><code>#   ifdef BOOST_WINDOWS_API
      const std::string string() const
      {
        std::string tmp;
        if (!m_pathname.empty())
     /*This is 412 line*/     path_traits::convert(&amp;*m_pathname.begin(), &amp;*m_pathname.begin()+m_pathname.size(),
          tmp);
        return tmp;
      }
  </code></pre>
  
  <p>What I am doing wrong and how to prevent this exception?</p>