#include #include #include #include #include #include #include #include boost::container::pmr::synchronized_pool_resource pool; boost::concurrent::sync_queue queue; void cleaner() { void * ptr; while ( queue.wait_pull(ptr) == boost::concurrent::queue_op_status::success ) { pool.deallocate(ptr, 512, 4); } } void worker() { struct sched_param param = { .sched_priority = 1 }; const int res = sched_setscheduler(0, SCHED_FIFO, ¶m); if ( res < 0 ) { perror("sched_setscheduler"); } for ( int i = 0; i < 1000; ++i ) { auto now = std::chrono::steady_clock::now(); auto p = pool.allocate(512, 4); auto end = std::chrono::steady_clock::now(); if ( std::chrono::duration_cast(end - now).count() > 1000 ) { std::cout << "failed " << i << std::endl; } queue.push(p); } } int main(int argc, char **argv) { unsigned nthreads = boost::thread::hardware_concurrency(); std::cout << "Running on " << nthreads << " threads " << std::endl; std::vector< boost::thread > thr; for ( int i = 0; i < nthreads; ++i ) { thr.emplace_back( worker ); } boost::thread c(cleaner); for ( auto & t : thr ) { t.join(); } queue.close(); c.join(); return 0; }