Software Open Access
BS_thread_pool.hpp
to avoid potential conflict with other thread pool libraries.#include "BS_thread_pool.hpp"
.thread_pool
class and the helper classes, are now located in the namespace BS
. This namespace will also be used for my other C++ projects, and is intended to ensure consistency between my projects while avoiding potential name conflicts with other libraries.BS::thread_pool
. Alternatively, it is possible to employ using BS::thread_pool
or even using namespace BS
and then invoke thread_pool
directly. Same for the BS::synced_stream
and BS::timer
helper classes.THREAD_POOL_VERSION
, which contains the version number and release date of the library, has been renamed to BS_THREAD_POOL_VERSION
to avoid potential conflicts.BS_THREAD_POOL_VERSION
.sleep_duration
has been removed. The thread pool now uses condition variables instead of sleep to facilitate waiting. This significantly improves performance (by 10%-50% in my testing), drastically decreases idle CPU utilization, and eliminates the need to set an optimal sleep time. This was a highly-requested change; see issue #1, issue #12, and pull request #23.sleep_duration
.submit()
have been merged. Now instead of two versions, one for functions with a return value and one for functions without a return value, there is just one version, which can accept any function. This makes the code more compact (and elegant). If a function with no return value is submitted, an std::future<void>
is returned (the previous version returned an std::future<bool>
)wait()
or get()
on the corresponding std::future<void>
.parallelize_loop()
now returns a future in the form of a new BS::multi_future
helper class template. The member function wait()
of this future allows waiting until all of the loop's blocks finish executing. In previous versions, calling parallelize_loop()
both parallelized the loop and waited for the blocks to finish; now it is possible to do other stuff while the loop executes.parallelize_loop()
no longer automatically blocks, you should either store the result in a BS::multi_future
object and call its wait()
member function, or simply call parallelize_loop().wait()
to reproduce the old behavior.parallelize_loop()
with functions that have return values and get these values from all blocks at once through the get()
member function of the BS::multi_future
.push_task()
have been merged. Now instead of two versions, one for functions with arguments and one for functions without arguments, there is just one version, which can accept any function.explicit
. See issue #28.submit()
now uses std::make_shared
instead of new
to create the shared pointer. This means only one memory allocation is performed instead of two, which should improve performance. In addition, all unique pointers are now created using std::make_unique
.BS::multi_future
, has been added. It's basically just a wrapper around std::vector<std::future<T>>
. This class is used by the new implementation of parallelize_loop()
to allow waiting for the entire loop, consisting of multiple tasks with their corresponding futures, to finish executing.BS::multi_future
can also be used independently to handle multiple futures at once. For example, you can now keep track of several groups of tasks by storing their futures inside separate BS::multi_future
objects and use either wait()
to wait for all tasks in a specific group to finish or get()
to get an std::vector
with the return values of every task in the group.BS::concurrency_t
, equal to the return type of std::thread::hardware_concurrency()
. This is probably pointless, since the C++ standard requires this to be unsigned int
, but it seems to me to make the code slightly more portable, in case some non-conforming compiler chooses to use a different integer type.BS_thread_pool_test.cpp
to avoid potential conflict with other thread pool libraries.EXIT_FAILURE
if any of the tests failed, for automation purposes. See pull request #42.check_task_monitoring()
. See pull request #43.parallelize_loop()
with a return value.count_unique_threads()
now uses futures (stored in a BS::multi_future<void>
object).std::vector
instead of matrices, for both consistency checks and benchmarks, in order to simplify the code and considerably reduce its length.README.md
:CITATION.bib
file (in BibTeX format) to the GitHub repository. You can use it to easily cite this package if you use it in any research papers.CITATION.cff
file (in YAML format) to the GitHub repository. This should add an option to get a citation in different formats directly from GitHub repository by clicking on "cite this repository" on the sidebar to the right.Name | Size | |
---|---|---|
bshoshany/thread-pool-v3.0.0.zip
md5:6af264bef3d5b1243ad5be777fe19da0 |
40.2 kB | Download |
All versions | This version | |
---|---|---|
Views | 741 | 121 |
Downloads | 23 | 2 |
Data volume | 621.5 kB | 80.3 kB |
Unique views | 683 | 109 |
Unique downloads | 13 | 2 |