#include #include #include #include #include #include #include using namespace std::chrono_literals; std::atomic run(true); std::atomic push(0), pop(0); boost::lockfree::stack s(10000); void work() { std::default_random_engine engine; while (run) { if (engine() & 1) { assert(s.push(0x12345678)); ++push; } else { int i; if (s.pop(i)) assert(i == 0x12345678); ++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; }