Protect globals.Stopping with RWMutex.

Make globals.Stopping unexported and wrap writes/reads with methods that lock
on a RWMutex.

Fixes #1025
I think this should have a more specific name, e.g. `stoppingMutex`.