The Go race detector doesn't like concurrent access to bool. This change moves the bool to use atomicBool, and extends atomicBool with the swap() method, to handle conditional use.