title: c++ threads execution time and executing thread in another thread
body: <p>I have a code, and i'm testing how much time will take an executing of 10 threads.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;thread&gt;
  #include &lt;chrono&gt;
  #include &lt;time.h&gt;
  using namespace std;
  
  void pause_thread(int n){
      this_thread::sleep_for(chrono::seconds(n));
      cout &lt;&lt; "pause of " &lt;&lt; n &lt;&lt; " seconds ended\n";
  }
  
  int main(){
      clock_t EndTime = clock();
      thread threads[10];
  
      cout &lt;&lt; "Spawning 10 threads...\n";
      for (int i = 0; i&lt;10; ++i)
          threads[i] = thread(pause_thread, i + 1);
  
      cout &lt;&lt; "Done spawning threads. Now waiting for them to join:\n";
      for (int i = 0; i&lt;10; ++i)
          threads[i].join();
  
      cout &lt;&lt; "All threads joined!\n";
      cout &lt;&lt; "==================================================\n";
      cout &lt;&lt; "Time of executing threads: " &lt;&lt; (double)(clock() - EndTime) / CLOCKS_PER_SEC &lt;&lt; endl;
  
      system("pause");
      return 0;
  }
  </code></pre>
  
  <p>The output is this:</p>
  
  <pre><code>Spawning 10 threads...
  Done spawning threads. Now waiting for them to join:
  pause of 1 seconds ended
  pause of 2 seconds ended
  pause of 3 seconds ended
  pause of 4 seconds ended
  pause of 5 seconds ended
  pause of 6 seconds ended
  pause of 7 seconds ended
  pause of 8 seconds ended
  pause of 9 seconds ended
  pause of 10 seconds ended
  All threads joined!
  ==================================================
  Time of executing threads: 10.041
  </code></pre>
  
  <p><strong>First question is:</strong> Why execution of the program takes 10,041 seconds if the pause between each thread is 1 second? What happened with the program and it took additional 0.041s on executing?
  <strong>Second question is:</strong> Is this right way to execute thread in another thread?</p>
  
  <pre><code>threads[i] = thread(...);
  </code></pre>
  
  <p>Is this mean that thread is in the thread? </p>
  
  <p>If not, how can it be done (to execute thread in another thread)?</p>