]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.3.3/doc/html/manual/bk01pt02ch06.html
Inital import
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.3.3 / doc / html / manual / bk01pt02ch06.html
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Chapter 6. Termination</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /><meta name="keywords" content="&#10;      ISO C++&#10;    , &#10;      library&#10;    " /><link rel="start" href="../spine.html" title="The GNU C++ Library Documentation" /><link rel="up" href="support.html" title="Part II. Support" /><link rel="prev" href="bk01pt02ch05.html" title="Chapter 5. Dynamic Memory" /><link rel="next" href="bk01pt02ch06s02.html" title="Verbose Terminate Handler" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 6. Termination</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="bk01pt02ch05.html">Prev</a> </td><th width="60%" align="center">Part II. Support</th><td width="20%" align="right"> <a accesskey="n" href="bk01pt02ch06s02.html">Next</a></td></tr></table><hr /></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="manual.support.termination"></a>Chapter 6. Termination</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="bk01pt02ch06.html#support.termination.handlers">Termination Handlers</a></span></dt><dt><span class="sect1"><a href="bk01pt02ch06s02.html">Verbose Terminate Handler</a></span></dt></dl></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="support.termination.handlers"></a>Termination Handlers</h2></div></div></div><p>
4       Not many changes here to <code class="filename">cstdlib</code>.  You should note that the
5       <code class="function">abort()</code> function does not call the
6       destructors of automatic nor static objects, so if you're
7       depending on those to do cleanup, it isn't going to happen.
8       (The functions registered with <code class="function">atexit()</code>
9       don't get called either, so you can forget about that
10       possibility, too.)
11     </p><p>
12       The good old <code class="function">exit()</code> function can be a bit
13       funky, too, until you look closer.  Basically, three points to
14       remember are:
15     </p><div class="orderedlist"><ol type="1"><li><p>
16         Static objects are destroyed in reverse order of their creation.
17         </p></li><li><p>
18         Functions registered with <code class="function">atexit()</code> are called in
19         reverse order of registration, once per registration call.
20         (This isn't actually new.)
21         </p></li><li><p>
22         The previous two actions are “<span class="quote">interleaved,</span>” that is,
23         given this pseudocode:
24         </p><pre class="programlisting">
25   extern "C or C++" void  f1 (void);
26   extern "C or C++" void  f2 (void);
27   
28   static Thing obj1;
29   atexit(f1);
30   static Thing obj2;
31   atexit(f2);
32 </pre><p>
33         then at a call of <code class="function">exit()</code>,
34         <code class="varname">f2</code> will be called, then
35         <code class="varname">obj2</code> will be destroyed, then
36         <code class="varname">f1</code> will be called, and finally
37         <code class="varname">obj1</code> will be destroyed. If
38         <code class="varname">f1</code> or <code class="varname">f2</code> allow an
39         exception to propagate out of them, Bad Things happen.
40         </p></li></ol></div><p>
41       Note also that <code class="function">atexit()</code> is only required to store 32
42       functions, and the compiler/library might already be using some of
43       those slots.  If you think you may run out, we recommend using
44       the <code class="function">xatexit</code>/<code class="function">xexit</code> combination from <code class="literal">libiberty</code>, which has no such limit.
45     </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="bk01pt02ch05.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="support.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="bk01pt02ch06s02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 5. Dynamic Memory </td><td width="20%" align="center"><a accesskey="h" href="../spine.html">Home</a></td><td width="40%" align="right" valign="top"> Verbose Terminate Handler</td></tr></table></div></body></html>