Protect globals.Stopping with RWMutex.

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

Fixes #1025