...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
~io_context();
On destruction, the io_context
performs the following sequence of operations:
svc
in the io_context
set, in reverse order of the beginning of service object lifetime,
performs svc->shutdown()
.
io_context
,
or any associated strand, are destroyed.
svc
in the io_context
set, in reverse order of the beginning of service object lifetime,
performs delete static_cast<io_context::service*>(svc)
.
The destruction sequence described above permits programs to simplify their
resource management by using shared_ptr<>
. Where an
object's lifetime is tied to the lifetime of a connection (or some other
sequence of asynchronous operations), a shared_ptr
to the
object would be bound into the handlers for all asynchronous operations
associated with it. This works as follows:
shared_ptr
references to the objects are destroyed.
io_context
function stop()
is called to terminate any run()
calls as soon as possible. The io_context
destructor defined above destroys all handlers, causing all shared_ptr
references to all connection objects to be destroyed.