title: Running boost asio io_service in a boost thread
body: <p>I'm using the boost daytime examples as a starter for a project that requires 2 way communication between machines and now need to launch the asio io_service in its own thread so I can pass data across seperatley. Here is the basis of my code: <a href="http://www.boost.org/doc/libs/1_35_0/doc/html/boost_asio/tutorial/tutdaytime7/src.html" rel="nofollow">http://www.boost.org/doc/libs/1_35_0/doc/html/boost_asio/tutorial/tutdaytime7/src.html</a></p>
  
  <p>It all works fine if I invoke the service in main with</p>
  
  <pre><code>io_service.run()
  </code></pre>
  
  <p>However, if I try to create a thread group and launch there like so:</p>
  
  <pre><code>int main()
  {
      boost::thread_group tgroup;
    try
    {
      boost::asio::io_service io_service;
      tcp_server server1(io_service);
      udp_server server2(io_service);
  
      tgroup.create_thread(boost::bind(&amp;boost::asio::io_service::run, &amp;io_service));
  
       std::cout &lt;&lt; "Server running on TCP port " &lt;&lt; tcpport &lt;&lt; std::endl &lt;&lt; "Server running on UDP port " &lt;&lt; udpport &lt;&lt; std::endl;
  
    }
      catch (std::exception&amp; e)
      {
          std::cerr &lt;&lt; e.what() &lt;&lt; std::endl;
      }
  
     tgroup.join_all();
    return 0;
  }
  </code></pre>
  
  <p>The code compiles and runs, the port numbers are quoted by cout correctly but it doesn't seem to open a listening port as the client gets a connection refused, although the server program seems to be ticking away awaiting connections.</p>
  
  <p>What is happening here please? </p>