Published January 4, 2026
| Version v5.1.0
Software
Open
A C++17 Thread Pool for High-Performance Scientific Computing
Authors/Creators
Description
v5.1.0 (2026-01-03)
- New/changed features:
- Added
detach_bulk()andsubmit_bulk()member functions to submit tasks in bulk. You can pass either a range of iterators or a container. The mutex protecting the task queue is locked only once for the entire bulk submission, which should improve performance when submitting a large number of tasks; if the tasks were submitted using individual calls todetach_task()orsubmit_task()instead, the mutex would need to be locked and unlocked for each task. detach_blocks()/detach_loop()/detach_sequence()andsubmit_blocks()/submit_loop()/submit_sequence()now usedetach_bulk()andsubmit_bulk(), respectively, under the hood for increased performance (the API remains the same). They have also been refactored using helper functions and custom function object classes to reduce code duplication.- All
submit_*member functions now use a C++17/20 polyfill forstd::move_only_functionwhen C++23 is not available (or when using libc++, which at the time of this release has not implemented it yet). This allows them to work without usingstd::shared_ptr, which should increase performance. - If the native extensions are enabled, a pool created with the default constructor will now only use the number of threads available to the process, as obtained from
BS::get_os_process_affinity(), which can be less than the number of hardware threads. See #161. - Since importing the C++ Standard Library using
import stdis now supported by all 3 major compilers, the library (and test program) will now useimport stdwhenever the macroBS_THREAD_POOL_IMPORT_STDis defined, as long as C++23 is enabled, without performing any additional checks for compiler or standard library support (aside from the workaround for GCC mentioned below). - The
BS::tpenumeration is now properly defined as anenum classwith the appropriate bitwise operators. - Removed the polyfills for
std::counting_semaphoreandstd::binary_semaphorefromBS_thread_pool.hpp, as they are not used by the library itself, to reduce the size of the header file. If you need them, you can copy them from the test programBS_thread_pool_test.cpp. - On Windows, if the native extensions are enabled,
WIN32_LEAN_AND_MEANis now defined before including<windows.h>to reduce compilation time.
- Added
- Bug fixes:
- The system macros
majorandminor(from<sys/sysmacros.h>on Linux) orminandmax(from<windows.h>on Windows) are now automatically undefined if they are detected, to prevent compilation errors. This was also done previously, but only under certain conditions; now it is done unconditionally, as some users reported issues. On Windows,NOMINMAXis now defined before including<windows.h>, but theminandmaxmacros are still undefined independently. BS::wait_deadlockis now only exported by the module if exceptions are enabled, preventing a compiler error. See #160.- Fixed a typo in
BS::thread_pool::submit_sequence()which caused the wrong number of futures to be reserved, potentially resulting in unnecessary reallocations. BS::multi_future<T>::wait_untilnow correctly waits using the specific clock type passed in the template parameter.- Fixed a bug where
reset()failed to notify worker threads if the pool was unpaused before resetting. get_os_thread_affinity()andset_os_thread_affinity()now returnstd::nulloptandfalse(respectively) on Android, as the API is not supported. See #163.
- The system macros
- Tests:
- The test program
BS_thread_pool_test.cppnow prints colored output for better readability. This can be disabled by setting theNO_COLORenvironment variable. - The test program now prints out the Mandelbrot set it generates, downsampled to fit in a terminal window (at 120 character width). This will be in 24-bit color in the terminal, and in monochrome using Unicode blocks in the log file. (If
NO_COLORis set, the terminal output will also be in monochrome.) - The test program now looks for
default_args.txtin both the current folder and the parent folder when reading default command line arguments.
- The test program
- Documentation:
- Added an example in
README.mdfor getting and setting process affinity. - Removed the suggestion in
README.mdto use the-pthreadflag on Linux/macOS, as it does not seem to be necessary in order to use the library, at least on the systems I tested with. If you are using a system that requires it, then you probably already know about it. - Updated the instructions in
README.mdfor compiling with GCC usingimport BS.thread_pool, and added instructions on how to compile thestdmodule with GNU libstdc++. - Fixed many typos and inconsistencies in
README.md.
- Added an example in
- Known issues:
- At the time of this release, there is a bug in Clang with libc++ where using
std::jthreadin a C++20 module causes a compilation error. As a workaround, until the bug is fixed, the thread pool library automatically falls back tostd::threadif it detects that Clang and libc++ are being used together with C++20 modules. This workaround can be disabled by definingBS_THREAD_POOL_DISABLE_WORKAROUNDSwhen compiling the module. - At the time of this release, there is a bug when using GCC with libstdc++ on Windows via MSYS2 where the
BS.thread_poolmodule doesn't compile if both native extensions andimport stdare enabled. As a workaround, until the bug is fixed, the thread pool library automatically falls back to header files if it detects that GCC and libstdc++ are being used together with the C++23stdmodule on Windows. This workaround can be disabled by definingBS_THREAD_POOL_DISABLE_WORKAROUNDSwhen compiling the module.
- At the time of this release, there is a bug in Clang with libc++ where using
- Development:
- The Python script I use for compiling the test program,
compile_cpp.py, has received numerous improvements:- The script now supports
import stdwith GCC in addition to Clang and MSVC. - The script now only recompiles the program if the source file(s), module(s), and optional additional dependencies (added using the flag
-n/--depsor thedepsfield incompile_cpp.yaml) have changed since the binary was created. Use-e/--forceto force recompilation. - The script now allows disabling exceptions by either defining
disable_exceptions: trueincompile_cpp.yamlor using the flag-x=true/--disable-exceptions=true(the flag overrides the YAML file). - The script can now compile modules independently using the
-l/--as-moduleflag. - The script can now clear the output folder using the
-b/--clear-outputflag (replaces theclear_folder.pyscript from the previous release). - The script can now test compilation using all possible combinations of compilers and C++ standards available in the system using the
-y/--try-allflag (replaces thetest_all.pyscript from the previous release). - The script now automatically detects the Visual Studio installation path on Windows.
- The script now implements a more robust mechanism for finding the
stdmodule. - The script now prints colored output for better readability. This can be disabled by setting the
NO_COLORenvironment variable. - The script no longer disables optimizations when compiling with GCC and modules (since that bug is fixed in recent versions of GCC).
- The script now supports
- Added a VS Code task to compile the test program (or the active file) with all available compilers and all relevant C++ standards, but without running it, to quickly check for compiler compatibility issues.
- The Python script I use for compiling the test program,
Notes
Files
bshoshany/thread-pool-v5.1.0.zip
Files
(174.5 kB)
| Name | Size | Download all |
|---|---|---|
|
md5:1d6cd246ae6978e1ff6681fb62cd6f22
|
174.5 kB | Preview Download |
Additional details
Related works
- Is supplement to
- Software: https://github.com/bshoshany/thread-pool/tree/v5.1.0 (URL)
Software
- Repository URL
- https://github.com/bshoshany/thread-pool