title: Thread joining issue
body: <p>I was reading some <a href="http://en.cppreference.com/w/cpp/thread/thread/join" rel="nofollow">manuals</a> about threads and I've come to a thought that the code they show is not safe:</p>
  
  <pre><code>std::cout &lt;&lt; "starting first helper...\n";
  std::thread helper1(foo);
  
  std::cout &lt;&lt; "starting second helper...\n";
  std::thread helper2(bar);
  
  std::cout &lt;&lt; "waiting for helpers to finish..." &lt;&lt; std::endl;
  helper1.join();   // #1 NOT SAFE
  helper2.join();   // #2 NOT SAFE
  </code></pre>
  
  <p>I believe this code is not absolutely safe. If I am not mistaking there is no guarantee that <code>helper1</code> and <code>helper2</code> are already in joinable state when control reaches lines marked as <code>#1</code> and <code>#2</code>. Threads could still be not launched and have no ids at this point. Which will cause an uncaught exception being thrown from <code>std::thread::join()</code></p>
  
  <p>I think the following code fixes the problem. Am I right?</p>
  
  <pre><code>std::cout &lt;&lt; "starting first helper...\n";
  std::thread helper1(foo);
  
  std::cout &lt;&lt; "starting second helper...\n";
  std::thread helper2(bar);
  
  std::cout &lt;&lt; "waiting for helpers to finish..." &lt;&lt; std::endl;
  while ( helper1.joinable() == false ) { }
  helper1.join();   // #1 SAFE
  while ( helper2.joinable() == false ) { }
  helper2.join();   // #2 SAFE
  </code></pre>