# ThreadPool-1 **Repository Path**: sunzz679_pku/ThreadPool-1 ## Basic Information - **Project Name**: ThreadPool-1 - **Description**: A fastest, exception-safety and pure C++17 thread pool. - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-05-19 - **Last Updated**: 2026-05-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Warnings Since commit `468129863ec65c0b4ede02e8581bea682351a6d2`, I move ThreadPool to C++17. (To use `std::apply`.)
In addition, **the rule of passing parameters to ThreadPool is different.**
Unlike before, which uses `std::bind`, **ThreadPool will not copy anything right now.**
All of ThreadPool does is forward (**no decay**).
This means you have to copy arguments by yourself before passing it to ThreadPool.
Below is demonstration, void test(int &i) { i=10; } int main() { int i(0); CThreadPool tp; tp.join(tp.add(test,i)); //before commit f66048ed999aa1b50dc956c4a728ff565042d761 cout< [Class view](https://github.com/Fdhvdu/ThreadPool/blob/master/README.md#class-view)
[Performance comparison](https://github.com/Fdhvdu/ThreadPool/blob/master/README.md#performance-comparison)
[Compiler](https://github.com/Fdhvdu/ThreadPool/blob/master/README.md#compiler)
[How to compile](https://github.com/Fdhvdu/ThreadPool/blob/master/README.md#how-to-compile)
[Compilation errors?](https://github.com/Fdhvdu/ThreadPool/blob/master/README.md#compilation-errors)
[Tutorial](https://github.com/Fdhvdu/ThreadPool/blob/master/README.md#tutorial)
[Future work](https://github.com/Fdhvdu/ThreadPool/blob/master/README.md#future-work) # Introduction This is a pure (which means it doesn't depend on any platform) and exception-safety C++ threadpool (so far, there is no standard threadpool in C++).
The goal of this project is to provide a `fastest`, `beautiful` and `easy-to-use` C++ threadpool library. # Class view Two classes CThreadPool, including the member function thread_id add(Func &&,Args &&...) void add_and_detach(Func &&,Args &&...) size_type empty() const noexcept void join(thread_id) void join_all() bool joinable(thread_id) const size_type size() const noexcept void wait_until_all_usable() const CThreadPool_Ret, including the member function thread_id add(Func &&,Args &&...) size_type empty() const noexcept Ret get(thread_id) size_type size() const noexcept bool valid(thread_id) const void wait(thread_id) const void wait_all() const Use the CThreadPool_Ret when you want to get the return value of function.
Use the CThreadPool when you don't care the return value of function.
`CThreadPool::add_and_detach` is faster (very) than `CThreadPool_Ret::add`. # Performance comparison [progschj/ThreadPool](https://github.com/progschj/ThreadPool), see [Comparison](comparison/README.md#result).
[Tyler-Hardin/thread_pool](https://github.com/Tyler-Hardin/thread_pool), see [Comparison](comparison/README.md#result).
P.S. About [bilash/threadpool](https://github.com/bilash/threadpool), I don't want to test a C-like code.
P.S. [nbsdx/ThreadPool](https://github.com/nbsdx/ThreadPool) cannot pass testing, see [README](comparison/nbsdx/README.md#warning).
P.S. [philipphenkel/threadpool](https://github.com/philipphenkel/threadpool) cannot pass testing, see [README](comparison/philipphenkel/README.md#warning).
P.S. [tghosgor/threadpool11](https://github.com/tghosgor/threadpool11) cannot pass testing, see [README](comparison/tghosgor/README.md#warning).
P.S. [mtrebi/thread-pool](https://github.com/mtrebi/thread-pool) cannot pass testing, see [README](comparison/mtrebi/README.md#warning).
See the [directory](comparison/) for more details. # Compiler Visual Studio 2017 15.5.5 g++ 7.2.1 clang++ 5.0.1 # How to compile You have to download [my lib](https://github.com/Fdhvdu/lib) first.
The directory should be look like ├── lib │ ├── header │ ├── LICENSE │ ├── README.md │ ├── src │ └── tutorial └── ThreadPool ├── comparison ├── header ├── LICENSE ├── README.md ├── src └── tutorial Don't forget to compile lib/src/Scope_guard.cpp. # Compilation errors? See [How to compile](https://github.com/Fdhvdu/ThreadPool/blob/master/README.md#how-to-compile) or email me # Tutorial I provide [example.cpp](tutorial/example.cpp) and [example_ret.cpp](tutorial/example_ret.cpp) to help you understand how to use this powerful thread pool
To use [example.cpp](tutorial/example.cpp):
g++ -std=c++17 tutorial/example.cpp src/* ../lib/src/Scope_guard.cpp To use [example_ret.cpp](tutorial/example_ret.cpp):
g++ -std=c++17 tutorial/example_ret.cpp src/IThreadPoolItemBase.cpp ../lib/src/Scope_guard.cpp # Future work add a non-block version of `CThreadPool::add`
work stealing