Setting limit on post queue size with Boost Asio?

后端 未结 4 1720
慢半拍i
慢半拍i 2021-02-20 18:09

I\'m using boost::asio::io_service as a basic thread pool. Some threads get added to io_service, the main thread starts posting handlers, the worker threads start r

4条回答
  •  遇见更好的自我
    2021-02-20 18:28

    you could use the strand object to put the events and put a delay in your main ? Is your program dropping out after all the work is posted? If so you can use the work object which will give you more control over when your io_service stops.

    you could always main check the state of the threads and have it wait untill one becomes free or something like that.

    //links

    http://www.boost.org/doc/libs/1_40_0/doc/html/boost_asio/reference/io_service__strand.html

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

    //example from the second link
    boost::asio::io_service io_service;
    boost::asio::io_service::work work(io_service);
    

    hope this helps.

提交回复
热议问题