Fix bugs that cause deadlock.

Initialize mutexes.