In my server application there is a pool of threads calling the io_service run() function. When a handler throws an exception the run function throws that exception too. Multiple threads call the run function in a try catch block. To restart the event handler I need to call run again but the documentation stated that restart() has to be called first. Restarting the io_service must assure that all run calls has been finished. How can I do that when other threads are still calling the run function?
Asked
Active
Viewed 282 times
2
-
It's all `run` calls for that specific `io_service` object. – Some programmer dude Feb 12 '18 at 10:35
-
There is only one io_service object and multiple threads call run on that single object – Gustavo Feb 12 '18 at 10:46
1 Answers
2
To restart the event handler I need to call run again but the documentation stated that restart() has to be called first.
No the documentation does not say that. You need to reset once the service had run out of work/been stopped. You did neither, so you do not need reset there.
Simply do as explained in this post Should the exception thrown by boost::asio::io_service::run() be caught? (which links to the docs)

sehe
- 374,641
- 47
- 450
- 633