1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>io_context::~io_context</title> 5<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../../boost_asio.html" title="Boost.Asio"> 8<link rel="up" href="../io_context.html" title="io_context"> 9<link rel="prev" href="wrap.html" title="io_context::wrap"> 10<link rel="next" href="../io_context__basic_executor_type.html" title="io_context::basic_executor_type"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="wrap.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../io_context.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../boost_asio.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../io_context__basic_executor_type.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h4 class="title"> 27<a name="boost_asio.reference.io_context._io_context"></a><a class="link" href="_io_context.html" title="io_context::~io_context">io_context::~io_context</a> 28</h4></div></div></div> 29<p> 30 <a class="indexterm" name="boost_asio.indexterm.io_context._io_context"></a> 31Destructor. 32 </p> 33<pre class="programlisting">~io_context(); 34</pre> 35<p> 36 On destruction, the <a class="link" href="../io_context.html" title="io_context"><code class="computeroutput">io_context</code></a> 37 performs the following sequence of operations: 38 </p> 39<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 40<li class="listitem"> 41 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> 42 set, in reverse order of the beginning of service object lifetime, 43 performs <code class="computeroutput">svc->shutdown()</code>. 44 </li> 45<li class="listitem"> 46 Uninvoked handler objects that were scheduled for deferred invocation 47 on the <a class="link" href="../io_context.html" title="io_context"><code class="computeroutput">io_context</code></a>, 48 or any associated strand, are destroyed. 49 </li> 50<li class="listitem"> 51 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> 52 set, in reverse order of the beginning of service object lifetime, 53 performs <code class="computeroutput">delete static_cast<io_context::service*>(svc)</code>. 54 </li> 55</ul></div> 56<h6> 57<a name="boost_asio.reference.io_context._io_context.h0"></a> 58 <span class="phrase"><a name="boost_asio.reference.io_context._io_context.remarks"></a></span><a class="link" href="_io_context.html#boost_asio.reference.io_context._io_context.remarks">Remarks</a> 59 </h6> 60<p> 61 The destruction sequence described above permits programs to simplify their 62 resource management by using <code class="computeroutput">shared_ptr<></code>. Where an 63 object's lifetime is tied to the lifetime of a connection (or some other 64 sequence of asynchronous operations), a <code class="computeroutput">shared_ptr</code> to the 65 object would be bound into the handlers for all asynchronous operations 66 associated with it. This works as follows: 67 </p> 68<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 69<li class="listitem"> 70 When a single connection ends, all associated asynchronous operations 71 complete. The corresponding handler objects are destroyed, and all 72 <code class="computeroutput">shared_ptr</code> references to the objects are destroyed. 73 </li> 74<li class="listitem"> 75 To shut down the whole program, the <a class="link" href="../io_context.html" title="io_context"><code class="computeroutput">io_context</code></a> 76 function <code class="computeroutput">stop()</code> is called to terminate any <code class="computeroutput">run()</code> 77 calls as soon as possible. The <a class="link" href="../io_context.html" title="io_context"><code class="computeroutput">io_context</code></a> 78 destructor defined above destroys all handlers, causing all <code class="computeroutput">shared_ptr</code> 79 references to all connection objects to be destroyed. 80 </li> 81</ul></div> 82</div> 83<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 84<td align="left"></td> 85<td align="right"><div class="copyright-footer">Copyright © 2003-2020 Christopher M. 86 Kohlhoff<p> 87 Distributed under the Boost Software License, Version 1.0. (See accompanying 88 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>) 89 </p> 90</div></td> 91</tr></table> 92<hr> 93<div class="spirit-nav"> 94<a accesskey="p" href="wrap.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../io_context.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../boost_asio.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../io_context__basic_executor_type.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a> 95</div> 96</body> 97</html> 98