c++boostthreadpoolboost-asioboost-thread

How to create a thread pool using boost in C++?


How do I create a thread pool using boost in C++, and how do I assign tasks to the threadpool?


Solution

  • Starting from boost 1.66.0, there is a thread_pool class:

    #include <boost/asio/thread_pool.hpp>
    #include <boost/asio/post.hpp>
    
    boost::asio::thread_pool pool(4); // 4 threads
    boost::asio::post(pool, [] {});
    pool.join();
    

    See the description.