ruipacheco ruipacheco - 1 month ago 7
C++ Question

Whats the benefit of using a single io_service over multiple threads?

I'm reading some of the answers regarding Asio and a patter that stands out, both in examples and here in SO, is to use a single io_service and share it between workers that would handle opening, sending and receiving messages over sockets.

Are there any benefits in sharing an io_service between multiple socket abstractions? Why not let each have their own io_service?

Answer

As far as I understand it, the io_service "owns" the resource. If you have one io_service handling all asio functions, then you can manage priorities. If you have multiple io_service instances, all "owning" the same resource, then they will clash.