⚠️ This library is no longer maintained. Please use the new and improved thread pool library athread for more features and better support.
The implement for thread pool. This is help for manage threads, tasks so easy and safely.
Required:
- C++ 14 is least
- CMake: minimum 3.20 to run examples.
- Tested on: Windows, Fedora
Just copy files in src/* to your project to using threadpool
mkdir build && cd build
cmake ..
cmake --build .
./thread_pool
Create thread pool
auto pool = ThreadPool(2, std::thread::hardware_concurrency(), 60s);
Pusk a task for thread pool
pool.push<RunnableExample>("#run 1000 miles#");
pool.push<RunnableExample>("#cooking breakfast#");
pool.emplace([](){
// do somethings
});
Notify stop thread pool
pool.terminate()
Wait until workers actually finish.
pool.wait()
Is there an easier way for you to use threadpool?
Enable TP_CONSOLE if you want to show activities of a threadpool in the console.