'Achieve fork-safety for C++ programs

I'm an infra engineer, whose main programming language is C++. I expose interface to Python users via pybinder. One of my headache derives from: threads in Python don't support parallelism via multi-threading (because of GIL), so have to achieve parallelism by fork/multi-processing, which breaks my program.

I want to know what should I do to achieve fork-safety? Several things I have tried:

  1. spawn new threads after fork, by atfork.
  2. close all file descriptors inherited in child process, which are inherited from parent process, and re-open them in the child process. This is also achieve by fork-hook.

But I cannot make my program fork-safe, a concrete example is: https://curl.se/libcurl/c/ephiperfifo.html

I want to know, what else should I do?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source