Creates an arbitrary number of threads for which work can be done on. Certain tasks can be completed asynchronously for which a thread pool can be used for. This particular implementation uses the future/promise model added in C++11. A C++14 compatible compiler is required for make_unique.
#include "thread_pool.h"
int my_work_function(int arg)
{
return arg;
}
// Create the thread pool. By default the thread count is the hardware concurrency value.
thread_pool<int> pool;
// Create some work. Pass any function arguments to the bind call.
std::future<int> future = pool.push(std::bind(&my_work_function, 1));
// Wait for the work to be completed
int result = future.get();
If the thread pool object goes out of scope, all threads will be stopped.
MIT