123456789101112131415161718192021222324252627
#include <thread> #include <iostream> #include <chrono> #include "Thread-Pool/ThreadPool.hpp" std::mutex mtx; int main(){ constexpr std::size_t N = 2; thread_pool pool(N); auto f = [](int& i) { std::this_thread::sleep_for (std::chrono::seconds(5)); mtx.lock(); i += 4; mtx.unlock(); }; int i = 0; pool.push(f, i); pool.push(f, i); pool.join(); std::cout << i; }
pool.push(f, std::ref(i));