Is it safe to fork from within a thread?

后端 未结 8 894
-上瘾入骨i
-上瘾入骨i 2020-11-28 04:04

Let me explain: I have already been developing an application on Linux which forks and execs an external binary and waits for it to finish. Results are communicated by shm f

8条回答
  •  -上瘾入骨i
    2020-11-28 05:03

    It's safe to fork in a multithreaded program as long as you are very careful about the code between fork and exec. You can make only re-enterant (aka asynchronous-safe) system calls in that span. In theory, you are not allowed to malloc or free there, although in practice the default Linux allocator is safe, and Linux libraries came to rely on it End result is that you must use the default allocator.

提交回复
热议问题