#include <condition_variable>
#include <iostream>
#include <mutex>
#include <stdexcept>
#include <thread>
int main() {
    std::mutex m; std::condition_variable space,entered;
    bool closed=false,waiting=false,rejected=false; int slot=7;
    std::thread producer([&] {
        std::unique_lock lock(m); waiting=true; entered.notify_one();
        space.wait(lock,[&]{return closed || slot==0;});
        if(closed) rejected=true; else slot=9;
    });
    {
        std::unique_lock lock(m); entered.wait(lock,[&]{return waiting;}); closed=true;
    }
    space.notify_all(); producer.join();
    if(!rejected || slot!=7) throw std::runtime_error("shutdown");
    std::cout<<"push_rejected="<<rejected<<" retained="<<slot<<'\n';
}
