Boost asio 运行 vs work(歧义)——work class 的目的是什么?

Boost asio run vs work (ambiguity) - what's the purpose of the work class?

正如您在此示例 UDP server 中所见,运行 方法将永远保持应用程序 运行ning。 (已测试)

所以不需要使用文档中提到的工作class

来自 boost 文档: 工作 class 用于通知 io_service 工作何时开始和结束。这确保了 io_service 对象的 run() 函数不会在工作正在进行时退出,并且当没有剩余未完成的工作时它会退出。

work class 已弃用,已被 executor_work_guard 取代。其目的已在 documentation:

中进行了解释

Some applications may need to prevent an io_context object's run() call from returning when there is no more work to do. For example, the io_context may be being run in a background thread that is launched prior to the application's asynchronous operations. The run() call may be kept running by creating an object of type boost::asio::executor_work_guard<io_context::executor_type> [...]