I’m new in boost programming, and I’ve been looking for a reason to use the io_service::work, but I can’t figure it out; in some of my tests I removed it and works fine.
I’m new in boost programming, and I’ve been looking for a reason to use
Share
The
io_service::run()will run operations as long as there are asynchronous operations to perform. If, at any time, there are no asynchronous operations pending (or handlers being invoked), therun()call will return.However, there are some designs that would prefer that the
run()call not exit until all work is done AND theio_servicehas explicitly been instructed that it’s okay to exit. That’s whatio_service::workis used for. By creating theworkobject (I usually do it on the heap and a shared_ptr), the io_service considers itself to always have something pending, and therefore therun()method will not return. Once I want the service to be able to exit (usually during shutdown), I will destroy the work object.