_io_context.html 5.64 KB
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>io_context::~io_context</title>
<link rel="stylesheet" href="../../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="../../../index.html" title="Asio">
<link rel="up" href="../io_context.html" title="io_context">
<link rel="prev" href="wrap.html" title="io_context::wrap">
<link rel="next" href="../io_context__basic_executor_type.html" title="io_context::basic_executor_type">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="asio C++ library" width="250" height="60" src="../../../asio.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="wrap.html"><img src="../../../prev.png" alt="Prev"></a><a accesskey="u" href="../io_context.html"><img src="../../../up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../home.png" alt="Home"></a><a accesskey="n" href="../io_context__basic_executor_type.html"><img src="../../../next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="asio.reference.io_context._io_context"></a><a class="link" href="_io_context.html" title="io_context::~io_context">io_context::~io_context</a>
</h4></div></div></div>
<p>
          <a class="indexterm" name="asio.indexterm.io_context._io_context"></a> 
Destructor.
        </p>
<pre class="programlisting">~io_context();
</pre>
<p>
          On destruction, the <a class="link" href="../io_context.html" title="io_context"><code class="computeroutput">io_context</code></a>
          performs the following sequence of operations:
        </p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
              For each service object <code class="computeroutput">svc</code> in the <a class="link" href="../io_context.html" title="io_context"><code class="computeroutput">io_context</code></a>
              set, in reverse order of the beginning of service object lifetime,
              performs <code class="computeroutput">svc-&gt;shutdown()</code>.
            </li>
<li class="listitem">
              Uninvoked handler objects that were scheduled for deferred invocation
              on the <a class="link" href="../io_context.html" title="io_context"><code class="computeroutput">io_context</code></a>,
              or any associated strand, are destroyed.
            </li>
<li class="listitem">
              For each service object <code class="computeroutput">svc</code> in the <a class="link" href="../io_context.html" title="io_context"><code class="computeroutput">io_context</code></a>
              set, in reverse order of the beginning of service object lifetime,
              performs <code class="computeroutput">delete static_cast&lt;io_context::service*&gt;(svc)</code>.
            </li>
</ul></div>
<h6>
<a name="asio.reference.io_context._io_context.h0"></a>
          <span><a name="asio.reference.io_context._io_context.remarks"></a></span><a class="link" href="_io_context.html#asio.reference.io_context._io_context.remarks">Remarks</a>
        </h6>
<p>
          The destruction sequence described above permits programs to simplify their
          resource management by using <code class="computeroutput">shared_ptr&lt;&gt;</code>. Where an
          object's lifetime is tied to the lifetime of a connection (or some other
          sequence of asynchronous operations), a <code class="computeroutput">shared_ptr</code> to the
          object would be bound into the handlers for all asynchronous operations
          associated with it. This works as follows:
        </p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
              When a single connection ends, all associated asynchronous operations
              complete. The corresponding handler objects are destroyed, and all
              <code class="computeroutput">shared_ptr</code> references to the objects are destroyed.
            </li>
<li class="listitem">
              To shut down the whole program, the <a class="link" href="../io_context.html" title="io_context"><code class="computeroutput">io_context</code></a>
              function <code class="computeroutput">stop()</code> is called to terminate any <code class="computeroutput">run()</code>
              calls as soon as possible. The <a class="link" href="../io_context.html" title="io_context"><code class="computeroutput">io_context</code></a>
              destructor defined above destroys all handlers, causing all <code class="computeroutput">shared_ptr</code>
              references to all connection objects to be destroyed.
            </li>
</ul></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2003-2020 Christopher M.
      Kohlhoff<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="wrap.html"><img src="../../../prev.png" alt="Prev"></a><a accesskey="u" href="../io_context.html"><img src="../../../up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../home.png" alt="Home"></a><a accesskey="n" href="../io_context__basic_executor_type.html"><img src="../../../next.png" alt="Next"></a>
</div>
</body>
</html>