The shutdown code has bothered me for a long time, with fShutdown and vnThreadsRunning and a bunch of ad-hoc Sleeps().
Reports of shutdown-on-exit bugs in 0.8 prompted me to clean it all up.
This pull reworks the way we keep track of threads, using boost::thread_groups or boost::thread pointers.
Instead of polling for a global fShutdown flag, threads now just MilliSleep(), wait on boost mutexes, or periodically call boost::this_thread::interruption_point(), and are interrupted using boost's thread interruption mechanisms.
All of the cleanup removes 400 lines of code, and, I hope, makes the code easier to follow.
Tested on OSX extensively, and compiled/tested lightly on Windows XP.