https://github.com/conorwilliams/threadpool
Light, fast, threadpool for C++20
https://github.com/conorwilliams/threadpool
cpp20 lock-free threadpool work-stealing
Last synced: 2 days ago
JSON representation
Light, fast, threadpool for C++20
- Host: GitHub
- URL: https://github.com/conorwilliams/threadpool
- Owner: ConorWilliams
- License: mpl-2.0
- Created: 2021-03-08T09:33:09.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-03-26T16:53:01.000Z (over 2 years ago)
- Last Synced: 2025-10-03T08:47:31.476Z (3 days ago)
- Topics: cpp20, lock-free, threadpool, work-stealing
- Language: C++
- Homepage:
- Size: 1.11 MB
- Stars: 104
- Watchers: 4
- Forks: 9
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `riften::Thiefpool`
A blazing-fast, lightweight, work-stealing thread-pool for C++20. Built on the lock-free concurrent [`riften::Deque`](https://github.com/ConorWilliams/ConcurrentDeque).
## Usage
```C++
#include "riften/thiefpool.hpp"// Create thread pool with 4 worker threads.
riften::Thiefpool pool(4);// Enqueue and return future.
auto result = pool.enqueue([](int x) { return x; }, 42);// Get result from future.
std::cout << result.get() << std::endl;
```Additionally, `riften::Thiefpool` supplies a detaching version of enqueue:
```C++
// Enqueue and return nothing
pool.enqueue_detach([](int x) { do_work(x); }, x);
```
Which elides the allocation of a `std::future`'s shared state.## Installation
The recommended way to consume this library is through [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake), just add:
```CMake
CPMAddPackage("gh:ConorWilliams/Threadpool#v2.1.1")
```
to your `CMakeLists.txt` and you're good to go!## Tests
To compile and run the tests:
```zsh
mkdir build && cd build
cmake ../test
make && make test
```