A simple implementation of a thread pool in C++.
BS Thread Pool is a header-only C++11 thread pool implementation. It provides a simple and efficient way to manage a pool of worker threads and execute tasks asynchronously.
wget https://raw.githubusercontent.com/bshoshany/thread-pool/master/include/BS_thread_pool.hppBoost Thread Pool is a part of the Boost C++ Libraries that provides a thread pool implementation. It allows you to manage a pool of worker threads and execute tasks asynchronously.
sudo apt-get install libboost-all-dev#include <boost/asio/thread_pool.hpp>
#include <boost/asio/post.hpp>
#include <iostream>
#include <chrono>
int main()
{
boost::asio::thread_pool pool(4);
for (int i = 0; i < 10; ++i) {
boost::asio::post(pool, [i] {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
std::cout << "Task " << i << " completed\n";
});
}
std::this_thread::sleep_for(std::chrono::milliseconds(500));
std::cout << "Shutting down thread pool...\n";
pool.join();
}