title: Implementing a simple, generic thread pool in C++11
body: <p>I want to create a thread pool for experimental purposes (and for the fun factor). It should be able to process a wide variety of tasks (so I can possibly use it in later projects). </p>
  
  <hr>
  
  <p>In my thread pool class I'm going to need some sort of task queue. Since the Standard Library provides <code>std::packaged_task</code> since the C++11 standard, my queue will look like <code>std::deque&lt;std::packaged_task&lt;?()&gt; &gt; task_queue</code>, so the client can push <code>std::packaged_task</code>s into the queue via some sort of public interface function (and then one of the threads in the pool will be notified with a condition variable to execute it, etc.).</p>
  
  <hr>
  
  <p>My question is related to the template argument of the <code>std::packaged_task&lt;?()&gt;</code>s in the deque. </p>
  
  <p>The function signature <code>?()</code> should be able to deal with any type/number of parameters, because the client can do something like: </p>
  
  <p><code>std::packaged_task&lt;int()&gt; t(std::bind(factorial, 342));
  thread_pool.add_task(t);</code></p>
  
  <p>So I don't have to deal with the type/number of parameters.</p>
  
  <p>But <strong>what should the return value be?</strong> (hence the question mark) </p>
  
  <ul>
  <li><p>If I make my whole thread pool class a template class, one instance
  of it will only be able to deal with tasks with a specific signature
  (like <code>std::packaged_task&lt;int()&gt;</code>).</p>
  
  <p><em>I want one thread pool object to be able to deal with any kind of task.</em> </p></li>
  <li><p>If I go with <code>std::packaged_task&lt;void()&gt;</code> and the function invoked
  returns an integer, or anything at all, then thats undefined behaviour.</p></li>
  </ul>