1

I am writing a server application.

  • For multi threading I using a thread pool similar to this one.
  • In the network interface I use sockets with async operations.
  • All sockets and the thread pool use the same io_service object.

My question is do async_read operations on multiple sockets "block" a thread from the thread pool or do they start additional threads or neither of these?

Community
  • 1
  • 1
WaeCo
  • 1,155
  • 1
  • 10
  • 21

1 Answers1

3

Neither. Each async_read operation is initially handled by the thread that called it. If forward progress can't be made without the socket being ready (because the other side needs to send or receive something), the async operation returns to the calling thread. Socket readiness is monitored by the "reactor", an internal part of boost that monitors sockets for readiness using the most efficient mechanisms supported by each platform. When the socket is ready and the operation can make forward progress, a "composed operation" is dispatched to the I/O service to continue the operation. When the operation completes, the thread that completes it calls the completion handler.

David Schwartz
  • 179,497
  • 17
  • 214
  • 278