I want to provide a global io_service
that is driven by one global thread. Simple enough, I just have the thread body call io_service::run()
. However, that doesn't work as run
(run_one
, poll
, poll_one
) return if there is no work to do. But, if the thread repeatedly calls run(), it will busy loop when there is nothing to do.
I'm looking for a way to get the thread to block while there isn't any work to be done in the io_service. I could add a global event to the mix for the thread to block on. However, that would require users of the io_service
to notify the event every time they used the service. Not the ideal solution.
Note: there are no actual globals and I never use events for concurrency I just simplified the problem down to my exact need. The real goal is a asio::deadline_timer
subclass that doesn't require an io_service
as a construction parameter.
You need to create an io_service::work
object.
See this section of the documentation:
Stopping the io_service from running out of work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With