boost :: asio :: io_service :: work

Boost Asio Io_service

Since io_service does not actively schedule threads, we need to manually allocate them. The common way is to allocate a thread to it, and then execute the run function. But the run function will exit after the io event is completed, the thread will terminate, and subsequent asynchronous io tasks based on this object cannot be scheduled. The solution to this problem is through aasio::io_service::workObject to guard io_service. In this way, even if all io tasks are executed, they will not exit and continue to wait for new io tasks. boost::asio::io_service io boost::asio::io_service::work work(io)