#include #include #include #include #include #include #include "stack.h" using namespace std::chrono_literals; std::atomic run(true); std::atomic push(0), pop(0); stack s; void work() { std::default_random_engine engine; while (run) { if (engine() & 1) { s.push(0x12345678); ++push; } else { try { assert(s.pop() == 0x12345678); } catch(stack::empty&) {} ++pop; } } } int main() { const std::size_t N = 8; std::thread workers[N]; for (auto& w: workers) w = std::thread(work); std::this_thread::sleep_for(100ms); run = false; for (auto& w: workers) w.join(); std::cout << push << ' ' << pop << ' ' << push + pop << std::endl; }