title: boost::asio io_service thread pool
body: <p>What's the proper usage of settings up a thread pool for io_service? These 2 statements from the <a href="http://www.boost.org/doc/libs/1_47_0/doc/html/boost_asio/reference/io_service.html" rel="noreferrer">documentation</a> are throwing me off:</p>
  <h3><a href="http://www.boost.org/doc/libs/1_47_0/doc/html/boost_asio/reference/io_service/run/overload2.html" rel="noreferrer">io_service::run</a></h3>
  <blockquote>
  <p>A normal exit from the run() function implies that the io_service object is stopped (the stopped() function returns true). Subsequent calls to run(), run_one(), poll() or poll_one() will return immediately unless there is a prior call to reset().</p>
  </blockquote>
  <h3><a href="http://www.boost.org/doc/libs/1_47_0/doc/html/boost_asio/reference/io_service/reset.html" rel="noreferrer">io_service::reset</a></h3>
  <blockquote>
  <p>This function must be called prior to any second or later set of invocations of the run(), run_one(), poll() or poll_one() functions when a previous invocation of these functions returned due to the io_service being stopped or running out of work.</p>
  </blockquote>
  <p>Here's what I'm currently doing:</p>
  <pre><code>boost::thread_group     m_Threads;
  boost::asio::io_service m_IoService;
  boost::barrier          m_Barrier(numThreads);
  
  for( unsigned int i = 0; i &lt; numThreads; ++i )
  {
      m_Threads.create_thread(
          [&amp;]()
          {
              for(;;)
              {
                  m_IoService.run();
  
                  if( m_Barrier.wait() )  //  will only return true for 1 thread
                  {
                      m_IoService.reset();
                  }
                  m_Barrier.wait();
              }
          });
  }
  
  m_IoService.stop();
  m_Threads.interrupt_all();
  m_Threads.join_all();
  </code></pre>
  <p>Everything seems to work fine if I just put <code>m_IoService.run()</code> in an infinite loop (which the documentation seems to indicate should <em>not</em> be the case). What's the <em>correct</em> way?</p>