title: C++ Getting "Debug Error R6010 -abort() has been called " when i assign promises to threads
body: <p>i'm getting error:<a href="http://i.stack.imgur.com/Up067.png" rel="nofollow">Debug Error R6010 -abort() has been called</a></p>
  
  <p>in my code :</p>
  
  <pre><code>bool ListFiles(wstring path, wstring mask, vector&lt;wstring&gt;&amp; files) {
  HANDLE hFind = INVALID_HANDLE_VALUE;
  WIN32_FIND_DATA ffd;
  wstring spec;
  stack&lt;wstring&gt; directories;
  
  directories.push(path);
  files.clear();
  
  while (!directories.empty()) {
      path = directories.top();
      spec = path + L"\\" + mask;
      directories.pop();
  
      hFind = FindFirstFile(spec.c_str(), &amp;ffd);
      if (hFind == INVALID_HANDLE_VALUE)  {
          return false;
      }
  
      do {
          if (wcscmp(ffd.cFileName, L".") != 0 &amp;&amp; wcscmp(ffd.cFileName, L"..") != 0) {
              if (ffd.dwFileAttributes &amp; FILE_ATTRIBUTE_DIRECTORY) {
                  directories.push(path + L"/" + ffd.cFileName);
              }
              else {
                  files.push_back(path + L"/" + ffd.cFileName);
              }
          }
      } while (FindNextFile(hFind, &amp;ffd) != 0);
  
      if (GetLastError() != ERROR_NO_MORE_FILES) {
          FindClose(hFind);
          return false;
      }
  
      FindClose(hFind);
      hFind = INVALID_HANDLE_VALUE;
  }
  
  return true;}
  
  void findText(std::string filename, std::string word , promise&lt;string&gt; &amp;prom) {
  std::ifstream f(filename);
  std::string s;
  std::string notFound = "no";
  bool found = false;
  if (!f) {
      std::cout &lt;&lt; "il file non esiste"&lt;&lt;std::endl;
  }
  while (f.good()) {
          std::getline(f, s);
          if (s.find(word, 0) != string::npos) {
              found = true;
          }
  
      }
  if (found) {
  
      //cout &lt;&lt; "Parola trovata in -&gt; " &lt;&lt; filename &lt;&lt; endl;
      prom.set_value_at_thread_exit(filename);
  }
  else {
      prom.set_value_at_thread_exit(notFound);
  }
  
  f.close();}
  int main(int argc, char* argv[]){
  //vector&lt;std::thread&gt; th;
  vector&lt;future&lt;string&gt;&gt; futures;
  vector&lt;wstring&gt; files;
  string search = "ciao";
  string notFound = "no";
  if (ListFiles(L"pds", L"*", files)) {
  
      for (vector&lt;wstring&gt;::iterator it = files.begin(); it != files.end(); ++it) {
          //wcout &lt;&lt; it-&gt;c_str() &lt;&lt; endl;
          wstring ws(it-&gt;c_str());
          string str(ws.begin(), ws.end());
          // Show String
          //cout &lt;&lt; str &lt;&lt; endl;
          //Creo una promise per ogni thread in cui andrò a cercare il risulato
          std::promise&lt;string&gt; prom;
          futures.push_back(prom.get_future());
          std::thread(findText,str,search,std::ref(prom)).detach();
  
      }
  }   
  
  for (int i = 0; i &lt; futures.size(); i++){
      futures.at(i).wait();
      if (futures.at(i).get().compare(notFound)!=0)
      cout &lt;&lt; "Parola trovata in -&gt;" &lt;&lt;futures.at(i).get()&lt;&lt;endl;
  }
  return 0;}
  </code></pre>
  
  <p>I've tried before without using promises and making each thread printing the name of file if word was found and it worked.
  So i don't know why using promises and future to retrive this value cause me this problem...
  I'm using VS 2013</p>