title: Several threads: catching the moment when they all finish work
body: <p>I have several threads, I need to catch the moment when they all finish work.
  How to do it?</p>
  
  <pre><code>for (int i = 1; i &lt; 3; i++) {
     std::thread threads1(countFile, i);
     i++;
     std::thread threads2(countFile, i);
     threads1.detach();
     threads2.detach();
  }
  
  // wait until all the threads run out---
  
  // to do next function ob object which uses by threads--
  </code></pre>