Added locks on the setpwalletRegistered functions in main.cpp and added an UnregisterAllWallets function.
Calling UnregisterAllWallets() instead of UnregisterWallet(pwalletMain) in init.cpp