1
0
mirror of https://github.com/bshoshany/thread-pool.git synced 2026-07-21 19:13:00 +04:00

Updated to v3.3.0

This commit is contained in:
Barak Shoshany
2022-08-03 14:23:38 -04:00
parent 670e3ab3ed
commit 67fad04348
6 changed files with 1323 additions and 166 deletions
+20
View File
@@ -16,6 +16,7 @@ Website: [https://baraksh.com/](https://baraksh.com/)<br />
GitHub: [https://github.com/bshoshany](https://github.com/bshoshany)<br />
* [Version history](#version-history)
* [v3.3.0 (2022-08-03)](#v330-2022-08-03)
* [v3.2.0 (2022-07-28)](#v320-2022-07-28)
* [v3.1.0 (2022-07-13)](#v310-2022-07-13)
* [v3.0.0 (2022-05-30)](#v300-2022-05-30)
@@ -33,6 +34,25 @@ GitHub: [https://github.com/bshoshany](https://github.com/bshoshany)<br />
## Version history
### 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](https://github.com/bshoshany/thread-pool/issues/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.
### v3.2.0 (2022-07-28)
* `BS_thread_pool.hpp`: