title: Threads in C, C++, C++0x, pthread and boost
body: <p>A question about threads in C/C++...</p>
  
  <p><strong>C++0x syntax</strong></p>
  
  <pre><code>#include &lt;thread&gt;
  
  void dummy() {}
  
  int main(int, char*[]) {
     std::thread x(dummy);
     std::thread y(dummy);
     ...
     return 0;
  }
  </code></pre>
  
  <p>How many threads are there? Two (x and y) or three (x, y and main)? Can I call <code>this_thread::yield()</code> in main? And what do I get from calling <code>this_thread::get_id()</code> in main?</p>
  
  <p><strong>pthread syntax</strong></p>
  
  <pre><code>#include &lt;pthread.h&gt;
  
  void dummy() {}
  
  int main(int, char*[]) {
     pthread_t x, y;
     pthread_create(&amp;x, NULL, &amp;dummy, NULL);
     pthread_create(&amp;y, NULL, &amp;dummy, NULL);
     ...
     return 0;
  }
  </code></pre>
  
  <p>How many threads are there? Two (x and y) or three (x, y and main)? Can I call <code>pthread_yield()</code> in main? And what do I get from calling <code>pthread_self()</code> in main?</p>
  
  <p><strong>boost syntax</strong></p>
  
  <pre><code>#include &lt;boost/thread&gt;
  
  void dummy() {}
  
  int main(int, char*[]) {
     boost::thread x(dummy);
     boost::thread y(dummy);
     ...
     return 0;
  }
  </code></pre>
  
  <p>How many threads are there? Two (x and y) or three (x, y and main)? Can I call <code>boost::this_thread::yield()</code> in main? And what do I get from calling <code>boost::this_thread::get_id()</code> in main?</p>