#include #include #include class Semaphor { private: int count; std::mutex mtx; std::condition_variable cond; public: Semaphor(int i) : count(i) {} void acquire() { std::unique_lock lock(mtx); while (count == 0) { // Solange keine Ressourcen verfügbar sind, warten cond.wait(lock); } count--; // Ressource belegen } void release() { std::unique_lock lock(mtx); count++; // Ressource freigeben cond.notify_one(); // Einen wartenden Thread aufwecken } };