I have been playing around with Boost.Asio and I want to be able to busy poll rather than simply perform an io_context.run(). My application currently consists of 2 io_context object each running on a separate thread of execution. All was well when i was using work guards with io_context.run(). When I switched to poll I experience premature exit of the application. I found out what polling exactly does so now my assumption is that it should be called in a tight loop (perhaps at the end of the tight loop). Is this the correct approach? For reference the reason I need to do this is because I need to achieve the lowest possible latency. Threads are running on isolated cores, with proper thread affinity setup. Now I need to make sure the whole system will busy poll. Thank you in advance!
I have tried to add work guards, which I later found out was not the correct approach. I also tried to run the polling in a very tight while loop but this just starved the async operations that “were” supposed to run on the same thread. Currently I just call poll at the end of my main while loop. You can imagine the code structured as follows:
co_spawn(ioc_,runner(),detached);
runner() {
while(true) {
// async
// logic
// async
ioc_.poll()
}
}
IvanYanakiev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2