Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

execution_context::notify_fork

Notify the execution_context of a fork-related event.

void notify_fork(
    fork_event event);

This function is used to inform the execution_context that the process is about to fork, or has just forked. This allows the execution_context, and the services it contains, to perform any necessary housekeeping to ensure correct operation following a fork.

This function must not be called while any other execution_context function, or any function associated with the execution_context's derived class, is being called in another thread. It is, however, safe to call this function from within a completion handler, provided no other thread is accessing the execution_context or its derived class.

Parameters

event

A fork-related event.

Exceptions

boost::system::system_error

Thrown on failure. If the notification fails the execution_context object should no longer be used and should be destroyed.

Example

The following code illustrates how to incorporate the notify_fork() function:

my_execution_context.notify_fork(execution_context::fork_prepare);
if (fork() == 0)
{
  // This is the child process.
  my_execution_context.notify_fork(execution_context::fork_child);
}
else
{
  // This is the parent process.
  my_execution_context.notify_fork(execution_context::fork_parent);
}
Remarks

For each service object svc in the execution_context set, performs svc->notify_fork();. When processing the fork_prepare event, services are visited in reverse order of the beginning of service object lifetime. Otherwise, services are visited in order of the beginning of service object lifetime.


PrevUpHomeNext