Reusing thread in loop c++
The easiest way is to use a waitable queue of std::function objects. Like this: #include <iostream> #include <thread> #include <mutex> #include <condition_variable> #include <queue> #include <functional> #include <chrono> class ThreadPool { public: ThreadPool (int threads) : shutdown_ (false) { // Create the specified number of threads threads_.reserve (threads); for (int i = 0; i < … Read more