Improve thread safety by adding protection mutexes.
Re-apply mutex safety in squashing from DM-1360