44 bool expected =
false;
45 if (!waiting.compare_exchange_strong(expected,
true)) {
46 throw std::runtime_error(
"Only one thread can wait at a time.");
48 std::unique_lock<std::mutex> lock(mtx);
49 cv.wait(lock, [&] {
return count.load(std::memory_order_acquire) == 0; });
52 waiting.store(
false, std::memory_order_release);