在我的服务器应用程序中,有一个线程池调用 io_service run() 函数。当处理程序抛出异常时,run 函数也会抛出该异常。多个线程在 try catch block 中调用 run 函数。要重新启动事件处理程序,我需要再次调用 run,但文档指出必须首先调用 restart()。重新启动 io_service 必须确保所有运行调用都已完成。当其他线程仍在调用 run 函数时,我该如何做到这一点?
最佳答案
To restart the event handler I need to call run again but the documentation stated that restart() has to be called first.
不文档没有这么说。一旦服务停止工作/停止,您就需要重置。您两者都没有做,所以您不需要在那里重置。
只需按照这篇文章 Should the exception thrown by boost::asio::io_service::run() be caught? 中的说明进行操作即可(链接到 docs )
关于c++11 - 从多个线程调用 boost::asio::io_service run 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48744311/