#pragma once #include #include #include class HCounter { static std::atomic ref; public: HCounter() { ++this->ref; } ~HCounter() { --this->ref; } static bool wait(int nCount) { while (--nCount && HCounter::ref.load()) { std::this_thread::sleep_for(std::chrono::milliseconds(1)); } return !HCounter::ref; } };