https://github.com/zhongruoyu/threadpp
A lightweight thread pool in C++17.
https://github.com/zhongruoyu/threadpp
cpp cpp17 thread-pool threading
Last synced: 9 months ago
JSON representation
A lightweight thread pool in C++17.
- Host: GitHub
- URL: https://github.com/zhongruoyu/threadpp
- Owner: ZhongRuoyu
- License: mit
- Created: 2021-11-04T18:01:41.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-07-10T02:37:46.000Z (almost 4 years ago)
- Last Synced: 2025-07-30T19:18:26.835Z (11 months ago)
- Topics: cpp, cpp17, thread-pool, threading
- Language: C++
- Homepage:
- Size: 42 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# threadpp
threadpp is a lightweight thread pool implementation in C++17 which provides
a task submission interface compatible with `std::thread`'s
[constructor](https://en.cppreference.com/w/cpp/thread/thread/thread).
Tasks are submitted and processed on a first-come, first-served basis, and
their results can be obtained via the `std::future` returned from submission.
## How to Use
To use threadpp in your project, you may either copy the sources under
directories [include](include) and [src](src) to your project, or build it as
a library and link it to your project. To build threadpp, read section "How to
Build".
Below is a simple usage example.
```c++
#include
#include
int FortyTwo() { return 42; }
void Foo() {
; // some task
}
int main() {
// create a ThreadPool with 3 workers
threadpp::ThreadPool pool(3);
// submit tasks
std::future forty_two = pool.Add(FortyTwo);
std::future foo = pool.Add(Foo);
std::future seven_is_even =
pool.Add([](int x) { return x % 2 == 0; }, 7);
// get results as needed
std::cout << forty_two.get() << std::endl;
// or simply left out the futures and wait for all tasks to finish
pool.Join();
}
```
More examples are available under the [examples](examples) directory.
## How to Build
To build threadpp, simply run `make`. The compiled library file
`libthreadpp.a` will then be created.
## License
Copyright (c) 2021 - 2022 Zhong Ruoyu. Licensed under
[the MIT License](LICENSE).