title: C++ 11 thread simple example
body: <p>I'm new to c++ and I was looking into some c++ cross-platform thread tutorials. I was looking into this: <a href="http://solarianprogrammer.com/2011/12/16/cpp-11-thread-tutorial/" rel="noreferrer">http://solarianprogrammer.com/2011/12/16/cpp-11-thread-tutorial/</a></p>
  
  <p>and was trying to execute the following code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;thread&gt;
  
  static const int num_threads = 10;
  
  //This function will be called from a thread
  
  void call_from_thread(int tid) {
      std::cout &lt;&lt; "Launched by thread " &lt;&lt; tid &lt;&lt; std::endl;
  }
  
  int main() {
      std::thread t[num_threads];
  
      //Launch a group of threads
      for (int i = 0; i &lt; num_threads; ++i) {
          t[i] = std::thread(call_from_thread, i);
      }
  
      std::cout &lt;&lt; "Launched from the main\n";
  
      //Join the threads with the main thread
      for (int i = 0; i &lt; num_threads; ++i) {
          t[i].join();
      }
  
      return 0;
  }
  </code></pre>
  
  <p>The output I'm getting is the following and I can not understand why:</p>
  
  <pre><code>syd@syd-HP-Compaq-dx7500-Microtower:~/Desktop$ ./ref
  Launched by thread Launched by thread Launched by thread Launched by thread Launched by thread 201
  Launched by thread 5
  
  Launched by thread 6
  4
  Launched by thread 7
  3
  
  Launched by thread 8
  Launched from the main
  Launched by thread 9
  </code></pre>
  
  <p>I understand that the numbers are random each time, but some times I get no numbers displayed and I wonder why?</p>