A thread pool for completing heterogenous tasks.
The thread pool is a class that completes given tasks using a set of worker threads. These threads pull tasks off of a task queue. Once finished with the task, the thread gets the next task if one is available, or waits for another task to be added. The tasks can be heterogenous, meaning any callable target can be added with any return type.
Example Usage:
double f1() { return 1.0; }
int f2(int val) { return val; }
int main()
{
std::future<double> result1 = pool.enqueue<double>(f1);
std::future<int> result2 = pool.enqueue<int>(std::bind(f2, 2));
std::future<std::string> result3 = pool.enqueue<std::string>([]() {return "string"; });
std::cout << "Result 1: " << result1.get() << std::endl;
std::cout << "Result 2: " << result2.get() << std::endl;
std::cout << "Result 3: " << result3.get() << std::endl;
}