title: Using boost::asio thread pool for general purpose tasks
body: <p>In <a href="http://mostlycoding.blogspot.de/2009/05/asio-library-has-been-immensely-helpful.html" rel="nofollow noreferrer">this blog</a> I found a pretty neat example on how to create a simple thread pool using boost::asio. I basically want to use it like this:</p>
  
  <pre><code>#include &lt;thread&gt;
  #include &lt;functional&gt;
  #include &lt;boost/asio.hpp&gt;
  
  int main ( int argc, char* argv[] ) {
      asio::io_service io_service;
      asio::io_service::work work(io_service);
  
      std::vector&lt;std::thread&gt; threadPool;
  
      for(size_t t = 0; t &lt; std::thread::hardware_concurrency(); t++){
          threadPool.push_back(thread(std::bind(&amp;asio::io_service::run, &amp;io_service)));
      }
  
      io_service.post(std::bind(an_expensive_calculation, 42));
      io_service.post(std::bind(a_long_running_task, 123));
  
      //Do some things with the main thread
  
      io_service.stop();
      for(std::thread&amp; t : threadPool) {
          t.join();
      }
  }
  </code></pre>
  
  <p>Boost::asio is, as far as I know, mainly made for network IO. However, I mainly want to use it for general purpose functions. Concurrency issues would be adressed using <code>asio::io_service::strand</code>.</p>
  
  <p>So my question: Is it a good idea to create a thread pool like this, even if my program does not use network IO? Are there any obvious performance losses compared to other thread pool implementations? If so, are there better implementations that are also as neat? </p>