title: boost::thread and creating a pool of them!
body: <p>boost::thread class has a default constructor which gives a "Not-a-thread", so what is </p>
  
  <p><code>boost::thread t1;</code></p>
  
  <p>good for? Can I give it a function to execute later in the code?</p>
  
  <p>and another question:</p>
  
  <p>I'm trying to write a little server which has a staged architecture (SEDA), there are a number of worker threads in each stage and the stages are connected with event queues. when i create the pool with 4 worker threads using boost::thread_group like this:
  (I've removed the condition variable on the queue to clean up here, and also assuming the size of the queue is always 4N.)</p>
  
  <pre><code>boost::thread_group threads;
  while(!event_queue.empty())
  {
      for(int i = 0; i &lt; 4; ++i)
      {
          threads.create_thread(event_queue.front());
          event_queue.pop();
      }
  
      threads.join_all();
  }
  </code></pre>
  
  <p>the thread_group keeps growing in size. what happens to those threads in the group which have finished and How can i reuse those threads and keep the thread_group size at 4?</p>
  
  <p>i saw <a href="https://stackoverflow.com/questions/2659065/c-boost-thread-reusing-threads">this question</a> and instead of the above code used this:</p>
  
  <pre><code>std::vector&lt;boost::shared_ptr&lt;boost::thread&gt;&gt; threads;
  while(!event_queue.empty())
  {
      for(int i = 0; i &lt; 4; ++i)
      {
          boost::shared_ptr&lt;boost::thread&gt; 
              thread(new boost::thread(event_queue.front());
          event_queue.pop();
          threads.push_back(thread);
      }
  
      for(int i = 0; i &lt; 4; ++i)
          threads[i]-&gt;join();
  
      threads.clear();
  }
  </code></pre>
  
  <p>so what's the difference and which one has a better performance? Will there be a memory leak? or is there another way to create a simple pool of threads?</p>
  
  <p>I'd appreciate any help. Thank you very much.</p>