Global mutexes/locks must be reinitialized in fork_end().

This change adds the global mutexes that are used in os-thread.c
to fork_end() so they are reinitialized after a fork() system
call. If they are not reinitialized they may be in a locked
state which may cause deadlock in the child process. This
changnge also cleans up various deadlock dectection code.