Simple c++ thread pool inspired by https://github.com/progschj/ThreadPool Capabilities
- Fixed-size thread pool
- Fair non-priority task queue
- Improvement over base: does not rely on system notify queue
In previous version you could face a problem, while having lots of heavy tasks and lots of quick task producers
Each task added to task queue produced
cv.notify_one(), which added new notification directly to system queue.
Modified version just uses task queue for storing tasks, ant there is one more background process ManageThread,
which efficiently manages notifications. So, you can have maximum of O(THREAD_COUNT) notifications in system queue
Tests
-
I didn't test it quite well, however, [test.cpp](test/test.cpp) provides example, when ThreadPool shows it's best in comparasion with threads spawning
Compilation
-
Supports CMake and simple make
cmake && make
or just
make -f Makefile.in
Examples
-
For exaples just see [test.cpp](test/test.cpp)Basic usage: ```c++ // create thread pool with 4 threads pool::ThreadPool tp(4); // add task to thread pool auto res = tp.AddTask([]() -> int { /* some stuff */ return rand(); }; // show result std::cout << res.get() << std::endl; ```