I have an application that has two threads. One thread forks on an event and other thread is doing something which results into a lot of getaddrinfo() calls. I am facing an issue where in some cases forked child hangs on a mutex inside getaddrinfo() call.
Now I understand that this only happens when child is forked while second thread in the parent process is in getaddinfo() call. This results into a deadlock because the child inherits the parent's lock but never releases it.
My question is how can one go about this issue when a system call itself is taking a lock? Well, one way I can fix it is by synchronizing the fork system call and getaddrinfo call in both the threads. But is there any other way to go about it?
Thanks!