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