title: c++ multithreading : terminate called recursively
body: <p>I'm pretty new to C++, and already involved in a rather complex project. The program is supposed to download a web site to be used offline. So to make it very simple what I've got is a "download manager" thread, creating as many "page downloader" threads as there as pages to download. In the same way, there also is an analysing thread tree. Here is the simplified code of the download manager :</p>
  
  <pre><code>void DlPage::manageDownload(){
      bool end=false;
      unique_lock&lt;mutex&gt; dlLck(dlMtx); // dlMtx is part of the shared data
      vector&lt;thread*&gt; downloads;
  
      cerr &lt;&lt; "Download manager : entering" &lt;&lt; endl;
      try{
          dlLck.lock();
      }catch (int e){
          cerr &lt;&lt; "Download Manager : unique_lock thrown exception: " &lt;&lt; e &lt;&lt; endl;
          exit(1);
      }
      cerr &lt;&lt; "Download manager : mutex locked" &lt;&lt; endl;
  
      while(!end){
          // wait for a new page to be available for dl
          cerr &lt;&lt; "Download manager : downloading page " &lt;&lt; pageId &lt;&lt; endl;
          // preparing data structures for download
          downloads.push_back(new thread(pageDownload, /*args*/));
          end=/*end condition*/;
      }
  
      dlLck.unlock();
      cerr &lt;&lt; "Download manager : mutex unlocked" &lt;&lt; endl;
  
      for(i=0;i&lt;downloads.size();i++){
          downloads[i]-&gt;join();
          delete downloads[i];
      }
      dbgStream() &lt;&lt; "Download manager : exiting" &lt;&lt; endl;
  }
  </code></pre>
  
  <p>And as output, I simply get :</p>
  
  <pre><code>Download manager : entering
  Analyse manager : entering // Analyse manager has the exact same structure as download.
  Main : Program launched // First page is added to the shared data and both managers are warned
  
  terminate called recursively // what I don't understand
  Aborted
  </code></pre>
  
  <p>At this point there is the main, and its 2 "manager" threads, created successfully as the output confirms it. And then, locking the mutex, even though any exception should be caught, crashes everything. And what's more, delivers an error message that should not appear in these circumstances. For what I understood, you'd get this message if the program can't destroy every object upon exiting a function.</p>
  
  <p>Thank you for your help,</p>
  
  <p>Jglukn</p>