Consider a Foo
that holds some resource
struct Foo
{
~Foo();
};
and a global std::vector<Foo>
. Perhaps stupid example, but it illustrates the problem well.
std::vector<Foo> bar;
Now, the processes fork
s.
If bar
is then only modified by the child process, then a call to exit
should be the proper thing to do within the child process. If calling _exit
, any Foo
:s in bar would leak. If the parent added some stuff to bar
before the fork, these object may be destroyed twice. Or maybe this is not a problem, because they should be considered as different objects.
What is the proper way of dealing with object lifetime together with a fork
. Is the only sane way of dealing with this problems to let the child exec
and start over?
I should notice that at this point in the program, there is guaranteed to be only one thread.