title: ThreadPool with boost::asio does not quit?
body: <p>I have the following minmal example of a thread pool made with boost::asio.</p>
  
  <pre><code>#include &lt;queue&gt;
  #include &lt;map&gt;
  
  #include &lt;boost/shared_ptr.hpp&gt;
  #include &lt;boost/asio/io_service.hpp&gt;
  #include &lt;boost/thread/thread.hpp&gt;
  #include &lt;boost/asio.hpp&gt;
  #include &lt;boost/date_time/posix_time/posix_time.hpp&gt; // remove me (only for io)
  
  class ThreadPool
  {
  public:
      void work_as_mainthread(void) { m_io_service.run(); }
  
      ThreadPool(int poolSize = 4) : timer(m_io_service)
      {
          timer.expires_from_now(boost::posix_time::seconds(1)); // this line does not affect the problem
          m_pWork.reset( new boost::asio::io_service::work(m_io_service) );
  
          for ( int i = 0; i &lt; poolSize; ++i)
              m_threadGroup.create_thread( boost::bind(&amp;boost::asio::io_service::run, &amp;m_io_service) );
      }
  
      ~ThreadPool()
      {
          m_pWork.reset();
          m_threadGroup.join_all();
      }
  
  private:
      boost::asio::io_service m_io_service;
      boost::asio::deadline_timer timer;
      boost::shared_ptr&lt;boost::asio::io_service::work&gt; m_pWork;
      boost::thread_group m_threadGroup;
  };
  
  int main()
  {
      int n_threads = 2;
      ThreadPool pool(n_threads);
      pool.work_as_mainthread();
      // this line is never reached...
      return 0;
  }
  </code></pre>
  
  <p>If you like, you can compile it like this:</p>
  
  <pre><code>g++ -Wall -g -lboost_thread -lboost_date_time -lboost_system main.cpp -o main
  </code></pre>
  
  <p>What makes me wonder is that the program does not stop. What I do is calling io_service::run, but without any "work" for it. io_services without work quit themselves, as said in the boost::asio docs. Now, why does my program never quit?</p>