views:

435

answers:

1
+1  A: 

In your client code, you invoke io_service::run() before there's any work for it to do, so your boost::thread exists immediately. This is fairly obvious if you attach a debugger to your client.

Instantiate an io_service::work instance prior to creating your thread to call io_service::run, that will ensure there's work to do.

This is fairly well documented in the io_service documentation

Stopping the io_service from running out of work Some applications may need to prevent an io_service object's run() call from returning when there is no more work to do. For example, the io_service may be being run in a background thread that is launched prior to the application's asynchronous operations. The run() call may be kept running by creating an object of type io_service::work:

http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/reference/io_service.html

Sam Miller