Boost logo

Boost Users :

Subject: [Boost-users] Multi Threaded Server with boost asio
From: mark pashley (mark.pashley_at_[hidden])
Date: 2012-01-15 09:53:34

I am looking at writing a multithreaded tcp server using boost ASIO. I have
read through the tutorials and had a look at some of the examples and just
want to check that my understanding is correct.

The server will accept connections then service requests from multiple

My understanding is as follows:

 1 The server uses "a single io_service and a thread pool calling
 2 All threads call io_service::run().
 3 The calls to io_service::run() are not within a strand, ergo completion
handlers can run simultaneously.
 4 When a request arrives one of the threads is chosen, it's read handler
will be called
 5 Another request may arrive,starting the read handler on a second thread
 6 When one of the threads has finished handling the request it calls
async_write, from within a strand
 7 Another thread also finishes processing its request, it also calls
async_write, from within a strand
 8 The writes to the io_service are serialised via the strand, ergo they
are thread safe.
 9 When the write operation completes the thread calls async_read()
10 This call is not protected by a strand and the thread will be used for
handling requests

Is my understanding correct?

View this message in context:
Sent from the Boost - Users mailing list archive at

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at