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
Congratulations, you found a defect in the standard. pthread_atfork
is fundamentally unable to solve the problem it was created to solve with mutexes, because the handler in the child is not permitted to perform any operations on them:
One potential workaround is to use POSIX semaphores in place of mutexes here. A semaphore does not have an owner, so if the parent process locks it (sem_wait
), both the parent and child processes can unlock (sem_post
) their respective copies without invoking any undefined behavior.
As a nice aside, sem_post
is async-signal-safe and thus definitely legal for the child to use.