How to use pthread_atfork() and pthread_once() to reinitialize mutexes in child processes

后端 未结 2 1679
北恋
北恋 2021-02-02 12:51

We have a C++ shared library that uses ZeroC\'s Ice library for RPC and unless we shut down Ice\'s runtime, we\'ve observed child processes hanging on random mutexes. The Ice r

2条回答
  •  野性不改
    2021-02-02 13:04

    I consider this a bug in the programs calling fork(). In a multi-threaded process, the child process should call only async-signal-safe functions. If a program wants to fork without exec, it should do so before creating threads.

    There isn't really a good solution for threaded fork()/pthread_atfork(). Some chunks of it appear to work, but this is not portable and liable to break across OS versions.

提交回复
热议问题