Use an atomic<bool> to store the monitor running flag.