What happens to other threads when one thread forks()?

后端 未结 5 1830
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-24 14:54

In C++ using pthreads, what happens to your other threads if one of your threads calls fork?

It appears that the threads do not follow. In my case, I am trying to c

5条回答
  •  被撕碎了的回忆
    2020-12-24 15:13

    Quoting from http://thorstenball.com/blog/2014/10/13/why-threads-cant-fork/

    If we call fork(2) in a multi-threaded environment the thread doing the call is now the main-thread in the new process and all the other threads, which ran in the parent process, are dead. And everything they did was left exactly as it was just before the call to fork(2).

    So we should think twice before using them

提交回复
热议问题