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