There is a newer version of the record available.

Published May 3, 2021 | Version v3.3.0
Software Open

A C++17 Thread Pool for High-Performance Scientific Computing

Description

v3.3.0 (2022-08-03)

  • BS_thread_pool.hpp:
    • The public member variable paused of BS::thread_pool has been made private for future-proofing (in case future versions implement a more involved pausing mechanism) and better encapsulation. It is now accessible only via the pause(), unpause(), and is_paused() member functions. In other words:
      • Replace pool.paused = true with pool.pause().
      • Replace pool.paused = false with pool.unpause().
      • Replace if (pool.paused) (or similar) with if (pool.is_paused()).
    • The public member variable f of BS::multi_future has been renamed to futures for clarity, and has been made private for encapsulation and simplification purposes. Instead of operating on the vector futures itself, you can now use the [] operator of the BS::multi_future to access the future at a specific index directly, or the push_back() member function to append a new future to the list. The size() member function tells you how many futures are currently stored in the object.
    • The explicit casts of std::endl and std::flush, added in v3.2.0 to enable flushing a BS::synced_stream, caused ODR (One Definition Rule) violations if BS_thread_pool.hpp was included in two different translation units, since they were mistakenly not defined as inline. To fix this, I decided to make them static members of BS::synced_stream instead of global variables, which also makes the code better organized in my opinion. These objects can now be accessed as BS::synced_stream::endl and BS::synced_stream::flush. I also added an example for how to use them in README.md. See #64.
  • BS_thread_pool_light.hpp:
    • This package started out as a very lightweight thread pool, but over time has expanded to include many additional features, and at the time of writing it has a total of 340 lines of code, including all the helper classes. Therefore, I have decided to bundle a light version of the thread pool in a separate and stand-alone header file, BS_thread_pool_light.hpp, with only 170 lines of code (half the size of the full package). This file does not contain any of the helper classes, only a new BS::thread_pool_light class, which is a minimal thread pool with only the 5 most basic member functions:
      • get_thread_count()
      • push_loop()
      • push_task()
      • submit()
      • wait_for_tasks()
    • A separate test program BS_thread_pool_light_test.cpp tests only the features of the lightweight BS::thread_pool_light class. In the spirit of minimalism, it does not generate a log file and does not do any benchmarks.
    • To be perfectly clear, each header file is 100% stand-alone. If you wish to use the full package, you only need BS_thread_pool.hpp, and if you wish to use the light version, you only need BS_thread_pool_light.hpp. Only a single header file needs to be included in your project.

Notes

If you use this package in published research, please cite it as follows.

Files

bshoshany/thread-pool-v3.3.0.zip

Files (60.2 kB)

Name Size Download all
md5:de781fc0b935d9cd4983718a307ff4a6
60.2 kB Preview Download

Additional details

Related works