BS::thread_pool: a fast, lightweight, modern, and easy-to-use C++17/C++20/C++23 thread pool library. This header file contains the entire library, and is the only file needed to use the library.
More...
#include <algorithm>
#include <chrono>
#include <condition_variable>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <future>
#include <iostream>
#include <limits>
#include <memory>
#include <mutex>
#include <optional>
#include <queue>
#include <string>
#include <thread>
#include <tuple>
#include <type_traits>
#include <utility>
#include <variant>
#include <vector>
Go to the source code of this file.
|
| struct | BS::version |
| | A struct used to store a version number, which can be checked and compared at compilation time. More...
|
| class | BS::move_only_function< R(Args...)> |
| | A simple polyfill for std::move_only_function, to be used if C++23 features are not available. Note that it does not have all the features of std::move_only_function, only the minimum needed for the thread pool library. More...
|
| struct | BS::move_only_function< R(Args...)>::func_concept |
| struct | BS::move_only_function< R(Args...)>::func_model< F > |
| struct | BS::pr_task |
| | A helper struct to store a task with an assigned priority. More...
|
| class | BS::multi_future< T > |
| | A helper class to facilitate waiting for and/or getting the results of multiple futures at once. More...
|
| class | BS::blocks< T > |
| | A helper class to divide a range into blocks. Used by detach_blocks(), submit_blocks(), detach_loop(), and submit_loop(). More...
|
| struct | BS::block_task< T, F, R > |
| | A function object class used by detach_blocks() and submit_blocks() to execute a block function over a specified range of indices. More...
|
| struct | BS::loop_task< T, F > |
| | A function object class used by detach_loop() and submit_loop() to execute a loop function over a specified range of indices. More...
|
| struct | BS::sequence_task< T, F, R > |
| | A function object class used by detach_sequence() and submit_sequence() to execute a sequence function over a specified index. More...
|
| struct | BS::task_and_future< R > |
| | A class that takes a function with a return value (but no arguments), and constructs a task with no return value along with a future used to retrieve the function's return value once the task is executed. Used by submit_task() and submit_bulk(). More...
|
| class | BS::this_thread |
| | A class used to obtain information about the current thread and, if native extensions are enabled, get/set its priority, affinity, or name. More...
|
| struct | BS::common_index_type< T1, T2, Enable > |
| | A meta-programming template to determine the common type of two integer types. Unlike std::common_type, this template maintains correct signedness. More...
|
| struct | BS::common_index_type< T1, T2, std::enable_if_t< std::is_signed_v< T1 > &&std::is_signed_v< T2 > > > |
| struct | BS::common_index_type< T1, T2, std::enable_if_t< std::is_unsigned_v< T1 > &&std::is_unsigned_v< T2 > > > |
| struct | BS::common_index_type< T1, T2, std::enable_if_t<(std::is_signed_v< T1 > &&std::is_unsigned_v< T2 >)||(std::is_unsigned_v< T1 > &&std::is_signed_v< T2 >)> > |
| class | BS::thread_pool< OptFlags > |
| | A fast, lightweight, modern, and easy-to-use C++17/C++20/C++23 thread pool class. More...
|
| class | BS::synced_stream |
| | A utility class to synchronize printing to one or more output streams by different threads. More...
|
|
| namespace | BS |
| | A namespace used by Barak Shoshany's projects.
|
|
| using | BS::opt_t = std::uint8_t |
| | The type used for the bitmask template parameter of the thread pool.
|
| using | BS::task_t = move_only_function<void()> |
| | The type of tasks in the task queue.
|
| using | BS::thread_t = std::thread |
| | The type of threads to use. In C++17 we use std::thread.
|
| using | BS::priority_t = std::int8_t |
| | A type used to indicate the priority of a task. Defined to be a signed integer with a width of exactly 8 bits (-128 to +127).
|
| template<typename T1, typename T2> |
| using | BS::common_index_type_t = typename common_index_type<T1, T2>::type |
| | A helper type alias to obtain the common type from the template BS::common_index_type.
|
| using | BS::light_thread_pool = thread_pool<tp::none> |
| | A fast, lightweight, modern, and easy-to-use C++17/C++20/C++23 thread pool class. This alias defines a thread pool with all optional features disabled.
|
| using | BS::priority_thread_pool = thread_pool<tp::priority> |
| | A fast, lightweight, modern, and easy-to-use C++17/C++20/C++23 thread pool class. This alias defines a thread pool with task priority enabled.
|
| using | BS::pause_thread_pool = thread_pool<tp::pause> |
| | A fast, lightweight, modern, and easy-to-use C++17/C++20/C++23 thread pool class. This alias defines a thread pool with pausing enabled.
|
| using | BS::wdc_thread_pool = thread_pool<tp::wait_deadlock_checks> |
| | A fast, lightweight, modern, and easy-to-use C++17/C++20/C++23 thread pool class. This alias defines a thread pool with wait deadlock checks enabled.
|
|
| constexpr bool | BS::thread_pool_module = false |
| | A flag indicating whether the thread pool library was compiled as a C++20 module.
|
| constexpr bool | BS::thread_pool_import_std = false |
| | A flag indicating whether the thread pool library imported the C++23 Standard Library module using import std.
|
| constexpr bool | BS::thread_pool_native_extensions = false |
| | A flag indicating whether the thread pool library's native extensions are enabled.
|
BS::thread_pool: a fast, lightweight, modern, and easy-to-use C++17/C++20/C++23 thread pool library. This header file contains the entire library, and is the only file needed to use the library.
██████ ███████ ████████ ██ ██ ██████ ███████ █████ ██████ ██████ ██████ ██████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██████ ███████ ██ ███████ ██████ █████ ███████ ██ ██ ██████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██████ ███████ ██ ██ ██ ██ ██ ███████ ██ ██ ██████ ███████ ██ ██████ ██████ ███████
- Author
- Barak Shoshany (barak.nosp@m.sh@g.nosp@m.mail..nosp@m.com) (https://baraksh.com/)
- Version
- 5.1.0
- Date
- 2026-01-03
- Copyright
- Copyright (c) 2021-2026 Barak Shoshany. Licensed under the MIT license. If you found this project useful, please consider starring it on GitHub! If you use this library in software of any kind, please provide a link to the GitHub repository https://github.com/bshoshany/thread-pool in the source code and documentation. If you use this library in published research, please cite it as follows: Barak Shoshany, "A C++17 Thread Pool for High-Performance Scientific Computing", doi:10.1016/j.softx.2024.101687, SoftwareX 26 (2024) 101687, arXiv:2105.00613
◆ BS_THREAD_POOL_DEFINE_BITWISE_OPERATOR
| #define BS_THREAD_POOL_DEFINE_BITWISE_OPERATOR |
( |
| ENUM, |
|
|
| OP ) |
Value: constexpr ENUM operator OP(const ENUM lhs, const ENUM rhs) noexcept \
{ \
return static_cast<ENUM>(static_cast<std::underlying_type_t<ENUM>>(lhs) OP static_cast<std::underlying_type_t<ENUM>>(rhs)); \
} \
constexpr ENUM& operator OP##=(ENUM& lhs, const ENUM rhs) noexcept \
{ \
return lhs = lhs OP rhs; \
}
273#define BS_THREAD_POOL_DEFINE_BITWISE_OPERATOR(ENUM, OP) \
274 constexpr ENUM operator OP(const ENUM lhs, const ENUM rhs) noexcept \
275 { \
276 return static_cast<ENUM>(static_cast<std::underlying_type_t<ENUM>>(lhs) OP static_cast<std::underlying_type_t<ENUM>>(rhs)); \
277 } \
278 constexpr ENUM& operator OP##=(ENUM& lhs, const ENUM rhs) noexcept \
279 { \
280 return lhs = lhs OP rhs; \
281 }
◆ BS_THREAD_POOL_IF_PAUSE_ENABLED
| #define BS_THREAD_POOL_IF_PAUSE_ENABLED template <bool P = pause_enabled, typename = std::enable_if_t<P>> |
◆ BS_THREAD_POOL_INIT_FUNC_CONCEPT
| #define BS_THREAD_POOL_INIT_FUNC_CONCEPT |
( |
| F | ) |
|
Value:typename F, typename = std::enable_if_t<std::is_invocable_v<F> || std::is_invocable_v<F, std::size_t>>
◆ BS_THREAD_POOL_OR_STOP_CONDITION
| #define BS_THREAD_POOL_OR_STOP_CONDITION || !workers_running |
◆ BS_THREAD_POOL_STOP_CONDITION
| #define BS_THREAD_POOL_STOP_CONDITION !workers_running |
◆ BS_THREAD_POOL_VERSION_MAJOR
| #define BS_THREAD_POOL_VERSION_MAJOR 5 |
◆ BS_THREAD_POOL_VERSION_MINOR
| #define BS_THREAD_POOL_VERSION_MINOR 1 |
◆ BS_THREAD_POOL_VERSION_PATCH
| #define BS_THREAD_POOL_VERSION_PATCH 0 |
◆ BS_THREAD_POOL_WAIT_TOKEN
| #define BS_THREAD_POOL_WAIT_TOKEN |
◆ BS_THREAD_POOL_WORKER_TOKEN
| #define BS_THREAD_POOL_WORKER_TOKEN |