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

Updated to v1.6

This commit is contained in:
Barak Shoshany
2021-05-26 09:00:51 -04:00
committed by GitHub
parent 31efea058c
commit bc66b8a222
3 changed files with 527 additions and 521 deletions
+3 -1
View File
@@ -75,7 +75,7 @@ As demonstrated in the performance tests [below](#performance-tests), using our
* **Fast:**
* Built from scratch with maximum performance in mind.
* Suitable for use in high-performance computing clusters with a very large number of CPU cores.
* Suitable for use in high-performance computing nodes with a very large number of CPU cores.
* Compact code, to reduce both compilation time and binary size.
* Reusing threads avoids the overhead of creating and destroying them for individual tasks.
* A task queue ensures that there are never more threads running in parallel than allowed by the hardware.
@@ -701,6 +701,8 @@ An interesting point to notice is that for **single-threaded** calculations (1 b
<a id="markdown-version-history" name="version-history"></a>
## Version history
* Version 1.6 (2021-05-26)
* Since MSVC does not interpret `and` as `&&` by default, the previous release did not compile with MSVC unless the `/permissive-` or `/Za` compiler flags were used. This has been fixed in this version, and the code now successfully compiles with GCC, Clang, and MSVC. See [this pull request](https://github.com/bshoshany/thread-pool/pull/10).
* Version 1.5 (2021-05-07)
* This library now has a DOI for citation purposes. Information on how to cite it in publications has been added to the source code and to `README.md`.
* Added GitHub badges to `README.md`.
+11 -7
View File
@@ -3,8 +3,8 @@
/**
* @file thread_pool.hpp
* @author Barak Shoshany (baraksh@gmail.com) (http://baraksh.com)
* @version 1.5
* @date 2021-05-07
* @version 1.6
* @date 2021-05-26
* @copyright Copyright (c) 2021 Barak Shoshany. Licensed under the MIT license. 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.5281/zenodo.4742687, arXiv:2105.00613 (May 2021)
*
@@ -136,7 +136,8 @@ public:
T start = (T)(t * block_size + first_index);
T end = (t == num_tasks - 1) ? last_index : (T)((t + 1) * block_size + first_index - 1);
blocks_running++;
push_task([start, end, &loop, &blocks_running] {
push_task([start, end, &loop, &blocks_running]
{
for (T i = start; i <= end; i++)
loop(i);
blocks_running--;
@@ -176,7 +177,8 @@ public:
template <typename F, typename... A>
void push_task(const F &task, const A &...args)
{
push_task([task, args...] { task(args...); });
push_task([task, args...]
{ task(args...); });
}
/**
@@ -212,7 +214,8 @@ public:
{
std::shared_ptr<std::promise<bool>> promise(new std::promise<bool>);
std::future<bool> future = promise->get_future();
push_task([task, args..., promise] {
push_task([task, args..., promise]
{
task(args...);
promise->set_value(true);
});
@@ -234,7 +237,8 @@ public:
{
std::shared_ptr<std::promise<R>> promise(new std::promise<R>);
std::future<R> future = promise->get_future();
push_task([task, args..., promise] { promise->set_value(task(args...)); });
push_task([task, args..., promise]
{ promise->set_value(task(args...)); });
return future;
}
@@ -339,7 +343,7 @@ private:
while (running)
{
std::function<void()> task;
if (!paused and pop_task(task))
if (!paused && pop_task(task))
{
task();
tasks_total--;