Why must io_service::reset() be called?

和自甴很熟 提交于 2019-12-01 06:45:28

When the io_service has been stopped:

  • all invocations of poll(), poll_one(), run(), and run_one() will return as soon as possible
  • subsequent calls to poll(), poll_one(), run(), and run_one() will return immediately without invoking any handlers or processing the event loop

Invoking 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() or poll_one() will return immediately until reset() 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().

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!