https://github.com/curve/poolparty
🌊 A simple, yet versatile C++ Thread-Pool library
https://github.com/curve/poolparty
Last synced: 5 months ago
JSON representation
🌊 A simple, yet versatile C++ Thread-Pool library
- Host: GitHub
- URL: https://github.com/curve/poolparty
- Owner: Curve
- License: mit
- Created: 2024-03-27T23:22:55.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-12-03T15:42:02.000Z (over 1 year ago)
- Last Synced: 2025-07-19T05:38:42.745Z (12 months ago)
- Language: CMake
- Homepage:
- Size: 96.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## 📃 Description
_poolparty_ is a simple and versatile C++20 thread-pool library.
> [!NOTE]
> This library does not handle exceptions. Please make sure to not throw from within tasks!
## 📦 Installation
* Using [CPM](https://github.com/cpm-cmake/CPM.cmake)
```cmake
CPMFindPackage(
NAME poolparty
VERSION 3.0.0
GIT_REPOSITORY "https://github.com/Curve/poolparty"
)
```
* Using FetchContent
```cmake
include(FetchContent)
FetchContent_Declare(poolparty GIT_REPOSITORY "https://github.com/Curve/poolparty" GIT_TAG v3.0.0)
FetchContent_MakeAvailable(poolparty)
target_link_libraries( cr::poolparty)
```
## 📖 Examples
```cpp
#include
#include
int expensive_calculation(int x)
{
std::this_thread::sleep_for(std::chrono::seconds(2));
return x + 1;
}
int main()
{
poolparty::pool pool{2};
// Pause execution
pool.pause();
auto fut1 = pool.submit(expensive_calculation, 1);
auto fut2 = pool.submit(expensive_calculation, 2);
// Let's add an additional thread
auto source = pool.add_thread();
auto fut3 = pool.submit(expensive_calculation, 3);
// Fire and forget
pool.forget([]() { expensive_calculation(100); });
// Resume execution
pool.resume();
std::cout << "Result: " << fut1.get() << ", " << fut2.get() << " and " << fut3.get() << std::endl;
// ...and remove the thread we've added
source.request_stop();
pool.cleanup();
return 0;
}
```
It's also possible to use a priority queue for more fine grained execution, see [tests](tests/priority.test.cpp):
https://github.com/Curve/poolparty/blob/4f58b719c99238985c1e99be6b07f893cfbd9c50/tests/priority.test.cpp#L48-L62