#ifndef stack_h #define stack_h 1 #include #include #include using namespace std::chrono_literals; template class stack { public: void push(T t) { semaphore.acquire(); container.push(t); semaphore.release(); } std::optional pop() { semaphore.acquire(); if (!container.empty()) { auto data = container.top(); container.pop(); semaphore.release(); return data; } else { semaphore.release(); return std::nullopt; } } private: std::binary_semaphore semaphore = std::binary_semaphore(1); std::stack container; }; #endif // stack_h