change static bool to static std::atomic<bool>