#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: { auto i = s.pop(); if (i) assert(*i == 0x12345678); break; } } ++ops; } } int main() { const size_t N = 4; 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'; }