#include #include #include #include #include void print() { std::cout << "print" << std::endl; } struct ThreadPool { void start() { boost::asio::io_service ioService; boost::thread_group threadpool; std::unique_ptr work = std::make_unique(ioService); threadpool.create_thread(boost::bind(&boost::asio::io_service::run, &ioService)); for (int i=0; i<100; ++i) { ioService.post(&print); } std::cout << "Post all calculation tasks" << std::endl; work.reset(); threadpool.join_all(); ioService.stop(); std::cout << "Finished all calculation tasks" << std::endl; } }; extern "C" void createthreadpool() { ThreadPool pool; pool.start(); }