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

1

9

As you can see here in this example UDP server, the run method will keep the application running forever. (tested)

So there is no need to use the work class as mentioned in the documentation

From boost documentation: The work class is used to inform the io_service when work starts and finishes. This ensures that the io_service object's run() function will not exit while work is underway, and that it does exit when there is no unfinished work remaining.

Merl answered 18/3, 2019 at 15:10 Comment(1)
There is no need in this example. This doesn't mean that its never needed.Currie
P
10

The work class is deprecated and has been replaced by executor_work_guard. Its purpose has been explained in the 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> [...]

Pyramid answered 18/3, 2019 at 15:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.