Add a lock for when the process forks

Deadlocks were occuring with DNS lookups because of the following case:

"The non-obvious problem in this approach is that at the moment of the
fork(2) call some threads may be in critical sections of code, doing
non-atomic operations protected by mutexes. In the child process the
threads just disappears and left data half-modified without any
possibility to "fix" them, there is no way to say what other threads
were doing and what should be done to make the data consistent.
Moreover: state of mutexes is undefined, they might be unusable and the
only way to use them in the child is to call pthread_mutex_init() to
reset them to a usable state. It's implementation dependent how mutexes
behave after fork(2) was called. On my Linux machine locked mutexes are
locked in the child."
[1] http://www.linuxprogrammingblog.com/threads-and-fork-think-twice-before-using-them

This thread-fork issue can be replicated quickly by having a background
thread call getaddrinfo() repeatedly, and then have the main thread
start a child process which itself calls getaddrinfo().
Timing-dependent, the child process may hang in a locked state. Example
script can be found here:
https://gist.github.com/andpol/ca7432afc09b1bc914f5