io_service::reset
documentation states that reset()
must be called before subsequent calls to run()
, run_one()
, poll()
or poll_one()
.
Questions:
assert
if it's neglected?Some context: I finished debugging some unit-tests that checked that called poll()
repeatedly without reset()
and was attempting to check the expected number of handlers was being executed each time. It appears that with enough calls to poll()
, all handlers are eventually executed in the order expected, but it takes more calls than you would otherwise expect. Correctly calling reset()
fixes the problem, but I'm curious to know if this is the only side effect of not calling reset()
, or if there are potentially worse effects such as dropping handlers or effects that might appear in a multi-threaded example.
When the io_service
has been stopped:
poll()
, poll_one()
, run()
, and run_one()
will return as soon as possiblepoll()
, poll_one()
, run()
, and run_one()
will return immediately without invoking any handlers or processing the event loopInvoking io_service::reset()
sets the io_service
to no longer be in a stopped state, allowing subsequent calls to poll()
, poll_one()
, run()
, and run_one()
to invoke handlers and process the event loop.
Why is this necessary?
It is necessary if one wishes to invoke handlers or process the event loop once the io_service
has been stopped explicitly via io_service.stop()
or implicitly by running out of work.
What behaviour might I expect if this step is neglected?
If io_service.stopped()
is true
, then subsequent calls to poll()
, poll_one()
, run()
, and run_one()
will not perform any work.
Why is this requirement not important enough to warrant an assert if it's neglected?
The io_service::reset()
documentation's use of the word "must" tends to set an overly critical tone without mentioning the consequences of not calling reset()
. The behavior described by io_service::stop()
is not critical enough to warrant an error:
Subsequent calls to
run()
,run_one()
,poll()
orpoll_one()
will return immediately untilreset()
is called.
For reset()
, the only hard requirement is to not call it when there are unfinished calls to poll()
, poll_one()
, run()
, and run_one()
.
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