Are multiple ASIO io_services a good thing?

后端 未结 3 1581
深忆病人
深忆病人 2021-02-01 19:19

I\'ve begun using Boost.ASIO for some simple network programming, my understanding of the library is not a great deal, so please bear with me and my newbie question.

At

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-01 19:54

    This discussion may be enlightening:

    http://thread.gmane.org/gmane.comp.lib.boost.asio.user/1300

    I don't have the code right here, but why would you use multiple io_services? I thought it used one io_service and multiple threads executing run on that one io_service.

    IIUC, each io_service owns a select/epoll/whatever queue, so having multiple io_services is akin to having multiple independent select/epoll loops. In some situations, eg. large numbers of sockets and multiple CPUs, this might help.

    Something I'm less sure about is with multiple threads all running io_service::run (with the same io_service). I think this just means the handlers are run concurrently, while the select/epoll/etc. loop is 'shared'. I think this is best for when your handlers are relatively long-running operations.

提交回复
热议问题