#include "stack.h" #include #include #include #include #include #include using namespace std::chrono_literals; std::random_device device; std::mt19937_64 engine(device()); std::bernoulli_distribution distribution; std::atomic run = true; std::atomic ops = 0; stack s; void work() { auto rng = std::bind(distribution, engine); while (run) { switch (rng()) { case 0: s.push(0x12345678); break; case 1: try { assert(s.pop() == 0x12345678); } catch (const stack::empty&) {} break; } ++ops; } } int main() { const size_t N = 1; std::thread threads[N]; for (auto& i: threads) i = std::thread(work); std::this_thread::sleep_for(10ms); run = false; for (auto& i: threads) i.join(); std::cout << ops << '\n'; }