refactor for threading

use atomic mechanism to signal exit as found in Client.* & PeerServer.*