• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>execution_context::notify_fork</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="../execution_context.html" title="execution_context">
9<link rel="prev" href="make_service.html" title="execution_context::make_service">
10<link rel="next" href="shutdown.html" title="execution_context::shutdown">
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="make_service.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../execution_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="shutdown.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.execution_context.notify_fork"></a><a class="link" href="notify_fork.html" title="execution_context::notify_fork">execution_context::notify_fork</a>
28</h4></div></div></div>
29<p>
30          <a class="indexterm" name="boost_asio.indexterm.execution_context.notify_fork"></a>
31Notify
32          the <a class="link" href="../execution_context.html" title="execution_context"><code class="computeroutput">execution_context</code></a>
33          of a fork-related event.
34        </p>
35<pre class="programlisting">void notify_fork(
36    fork_event event);
37</pre>
38<p>
39          This function is used to inform the <a class="link" href="../execution_context.html" title="execution_context"><code class="computeroutput">execution_context</code></a>
40          that the process is about to fork, or has just forked. This allows the
41          <a class="link" href="../execution_context.html" title="execution_context"><code class="computeroutput">execution_context</code></a>,
42          and the services it contains, to perform any necessary housekeeping to
43          ensure correct operation following a fork.
44        </p>
45<p>
46          This function must not be called while any other <a class="link" href="../execution_context.html" title="execution_context"><code class="computeroutput">execution_context</code></a>
47          function, or any function associated with the execution_context's derived
48          class, is being called in another thread. It is, however, safe to call
49          this function from within a completion handler, provided no other thread
50          is accessing the <a class="link" href="../execution_context.html" title="execution_context"><code class="computeroutput">execution_context</code></a>
51          or its derived class.
52        </p>
53<h6>
54<a name="boost_asio.reference.execution_context.notify_fork.h0"></a>
55          <span class="phrase"><a name="boost_asio.reference.execution_context.notify_fork.parameters"></a></span><a class="link" href="notify_fork.html#boost_asio.reference.execution_context.notify_fork.parameters">Parameters</a>
56        </h6>
57<div class="variablelist">
58<p class="title"><b></b></p>
59<dl class="variablelist">
60<dt><span class="term">event</span></dt>
61<dd><p>
62                A fork-related event.
63              </p></dd>
64</dl>
65</div>
66<h6>
67<a name="boost_asio.reference.execution_context.notify_fork.h1"></a>
68          <span class="phrase"><a name="boost_asio.reference.execution_context.notify_fork.exceptions"></a></span><a class="link" href="notify_fork.html#boost_asio.reference.execution_context.notify_fork.exceptions">Exceptions</a>
69        </h6>
70<div class="variablelist">
71<p class="title"><b></b></p>
72<dl class="variablelist">
73<dt><span class="term">boost::system::system_error</span></dt>
74<dd><p>
75                Thrown on failure. If the notification fails the <a class="link" href="../execution_context.html" title="execution_context"><code class="computeroutput">execution_context</code></a>
76                object should no longer be used and should be destroyed.
77              </p></dd>
78</dl>
79</div>
80<h6>
81<a name="boost_asio.reference.execution_context.notify_fork.h2"></a>
82          <span class="phrase"><a name="boost_asio.reference.execution_context.notify_fork.example"></a></span><a class="link" href="notify_fork.html#boost_asio.reference.execution_context.notify_fork.example">Example</a>
83        </h6>
84<p>
85          The following code illustrates how to incorporate the <code class="computeroutput">notify_fork()</code>
86          function:
87        </p>
88<pre class="programlisting">my_execution_context.notify_fork(execution_context::fork_prepare);
89if (fork() == 0)
90{
91  // This is the child process.
92  my_execution_context.notify_fork(execution_context::fork_child);
93}
94else
95{
96  // This is the parent process.
97  my_execution_context.notify_fork(execution_context::fork_parent);
98}
99</pre>
100<h6>
101<a name="boost_asio.reference.execution_context.notify_fork.h3"></a>
102          <span class="phrase"><a name="boost_asio.reference.execution_context.notify_fork.remarks"></a></span><a class="link" href="notify_fork.html#boost_asio.reference.execution_context.notify_fork.remarks">Remarks</a>
103        </h6>
104<p>
105          For each service object <code class="computeroutput">svc</code> in the <a class="link" href="../execution_context.html" title="execution_context"><code class="computeroutput">execution_context</code></a>
106          set, performs <code class="computeroutput">svc-&gt;notify_fork();</code>. When processing the
107          fork_prepare event, services are visited in reverse order of the beginning
108          of service object lifetime. Otherwise, services are visited in order of
109          the beginning of service object lifetime.
110        </p>
111</div>
112<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
113<td align="left"></td>
114<td align="right"><div class="copyright-footer">Copyright © 2003-2020 Christopher M.
115      Kohlhoff<p>
116        Distributed under the Boost Software License, Version 1.0. (See accompanying
117        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>)
118      </p>
119</div></td>
120</tr></table>
121<hr>
122<div class="spirit-nav">
123<a accesskey="p" href="make_service.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../execution_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="shutdown.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
124</div>
125</body>
126</html>
127