-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
77 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ Email: <[email protected]>\ | |
Website: <https://baraksh.com/>\ | ||
GitHub: <https://github.com/bshoshany> | ||
|
||
This is the complete documentation for v4.0.0 of the library, released on 2023-12-27. | ||
This is the complete documentation for v4.0.1 of the library, released on 2023-12-28. | ||
|
||
* [Introduction](#introduction) | ||
* [Motivation](#motivation) | ||
|
@@ -220,19 +220,25 @@ It is generally unnecessary to change the number of threads in the pool after it | |
### Finding the version of the library | ||
If desired, the version of this library may be read during compilation time from the macro `BS_THREAD_POOL_VERSION`. The value will be a string containing the version number and release date. For example: | ||
If desired, the version of this library may be read during compilation time from the following three macros: | ||
```cpp | ||
std::cout << "Thread pool library version is " << BS_THREAD_POOL_VERSION << ".\n"; | ||
* `BS_THREAD_POOL_VERSION_MAJOR` - indicates the major version. | ||
* `BS_THREAD_POOL_VERSION_MINOR` - indicates the minor version. | ||
* `BS_THREAD_POOL_VERSION_PATCH` - indicates the patch version. | ||
```cpp | ||
std::cout << "Thread pool library version is " << BS_THREAD_POOL_VERSION_MAJOR << '.' << BS_THREAD_POOL_VERSION_MINOR << '.' << BS_THREAD_POOL_VERSION_PATCH << ".\n"; | ||
``` | ||
|
||
Sample output: | ||
|
||
```none | ||
Thread pool library version is v4.0.0 (2023-12-27). | ||
Thread pool library version is 4.0.1. | ||
``` | ||
|
||
This can be used, for example, to allow the same code to work with several incompatible versions of the library. | ||
This can be used, for example, to allow the same code base to work with several incompatible versions of the library using `#if` directives. | ||
|
||
**Note:** This feature is only available starting with v4.0.1. Earlier releases of this library do not define these macros. | ||
|
||
## Submitting tasks to the queue | ||
|
||
|
@@ -948,7 +954,13 @@ Aside from using `BS::multi_future<T>` to track the execution of parallelized lo | |
## Utility classes | ||
The optional header file `BS_thread_pool_utils.hpp` contains several useful utility classes. These are not necessary for using the thread pool itself; `BS_thread_pool.hpp` is the only header file required. However, the utility classes can make writing multithreading code more convenient. The version of the utilities header file can be found by checking the macro `BS_THREAD_POOL_UTILS_VERSION`. | ||
The optional header file `BS_thread_pool_utils.hpp` contains several useful utility classes. These are not necessary for using the thread pool itself; `BS_thread_pool.hpp` is the only header file required. However, the utility classes can make writing multithreading code more convenient. | ||
As with [the main header file](#finding-the-version-of-the-library), the version of the utilities header file can be found by checking three macros: | ||
* `BS_THREAD_POOL_UTILS_VERSION_MAJOR` - indicates the major version. | ||
* `BS_THREAD_POOL_UTILS_VERSION_MINOR` - indicates the minor version. | ||
* `BS_THREAD_POOL_UTILS_VERSION_PATCH` - indicates the patch version. | ||
### Synchronizing printing to a stream with `BS::synced_stream` | ||
|
@@ -1640,11 +1652,11 @@ BS::thread_pool pool(1); | |
|
||
int main() | ||
{ | ||
pool.detach_task( [] { sync_out.println("This task will execute third."); }, BS::pr::normal); | ||
pool.detach_task( [] { sync_out.println("This task will execute fifth."); }, BS::pr::lowest); | ||
pool.detach_task( [] { sync_out.println("This task will execute second."); }, BS::pr::high); | ||
pool.detach_task( [] { sync_out.println("This task will execute first."); }, BS::pr::highest); | ||
pool.detach_task( [] { sync_out.println("This task will execute fourth."); }, BS::pr::low); | ||
pool.detach_task([] { sync_out.println("This task will execute third."); }, BS::pr::normal); | ||
pool.detach_task([] { sync_out.println("This task will execute fifth."); }, BS::pr::lowest); | ||
pool.detach_task([] { sync_out.println("This task will execute second."); }, BS::pr::high); | ||
pool.detach_task([] { sync_out.println("This task will execute first."); }, BS::pr::highest); | ||
pool.detach_task([] { sync_out.println("This task will execute fourth."); }, BS::pr::low); | ||
} | ||
``` | ||
|
@@ -1771,7 +1783,7 @@ If you are using the [Conan](https://conan.io/) C/C++ package manager, you can e | |
|
||
```ini | ||
[requires] | ||
bshoshany-thread-pool/4.0.0 | ||
bshoshany-thread-pool/4.0.1 | ||
``` | ||
|
||
To update the package to the latest version, simply change the version number. Please refer to [this package's page on ConanCenter](https://conan.io/center/recipes/bshoshany-thread-pool) for more information. | ||
|
@@ -1798,7 +1810,7 @@ If you are using [CMake](https://cmake.org/), you can install `BS::thread_pool` | |
CPMAddPackage( | ||
NAME BS_thread_pool | ||
GITHUB_REPOSITORY bshoshany/thread-pool | ||
VERSION 4.0.0) | ||
VERSION 4.0.1) | ||
add_library(BS_thread_pool INTERFACE) | ||
target_include_directories(BS_thread_pool INTERFACE ${BS_thread_pool_SOURCE_DIR}/include) | ||
``` | ||
|
@@ -1833,7 +1845,7 @@ include(${CPM_DOWNLOAD_LOCATION}) | |
CPMAddPackage( | ||
NAME BS_thread_pool | ||
GITHUB_REPOSITORY bshoshany/thread-pool | ||
VERSION 4.0.0) | ||
VERSION 4.0.1) | ||
add_library(BS_thread_pool INTERFACE) | ||
target_include_directories(BS_thread_pool INTERFACE ${BS_thread_pool_SOURCE_DIR}/include) | ||
add_executable(my_project main.cpp) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,8 @@ | |
/** | ||
* @file BS_thread_pool.hpp | ||
* @author Barak Shoshany ([email protected]) (http://baraksh.com) | ||
* @version 4.0.0 | ||
* @date 2023-12-27 | ||
* @version 4.0.1 | ||
* @date 2023-12-28 | ||
* @copyright Copyright (c) 2023 Barak Shoshany. Licensed under the MIT license. If you found this project useful, please consider starring it on GitHub! If you use this library in software of any kind, please provide a link to the GitHub repository https://github.com/bshoshany/thread-pool in the source code and documentation. 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) | ||
* | ||
* @brief BS::thread_pool: a fast, lightweight, and easy-to-use C++17 thread pool library. This header file contains the main thread pool class and some additional classes and definitions. No other files are needed in order to use the thread pool itself. | ||
|
@@ -31,8 +31,10 @@ | |
* @brief A namespace used by Barak Shoshany's projects. | ||
*/ | ||
namespace BS { | ||
// A macro containing the version of the thread pool library. | ||
#define BS_THREAD_POOL_VERSION "v4.0.0 (2023-12-27)" | ||
// Macros indicating the version of the thread pool library. | ||
#define BS_THREAD_POOL_VERSION_MAJOR 4 | ||
#define BS_THREAD_POOL_VERSION_MINOR 0 | ||
#define BS_THREAD_POOL_VERSION_PATCH 1 | ||
|
||
class thread_pool; | ||
|
||
|
@@ -138,12 +140,12 @@ namespace this_thread { | |
/** | ||
* @brief A `thread_local` object used to obtain information about the index of the current thread. | ||
*/ | ||
thread_local thread_info_index get_index; | ||
inline thread_local thread_info_index get_index; | ||
|
||
/** | ||
* @brief A `thread_local` object used to obtain information about the thread pool that owns the current thread. | ||
*/ | ||
thread_local thread_info_pool get_pool; | ||
inline thread_local thread_info_pool get_pool; | ||
} // namespace this_thread | ||
|
||
/** | ||
|
@@ -952,8 +954,8 @@ class [[nodiscard]] thread_pool | |
const size_t total_size = static_cast<size_t>(index_after_last - first_index); | ||
if (num_blocks > total_size) | ||
num_blocks = total_size; | ||
block_size = static_cast<size_t>(total_size / num_blocks); | ||
remainder = static_cast<size_t>(total_size % num_blocks); | ||
block_size = total_size / num_blocks; | ||
remainder = total_size % num_blocks; | ||
if (block_size == 0) | ||
{ | ||
block_size = 1; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,8 @@ | |
/** | ||
* @file BS_thread_pool_utils.hpp | ||
* @author Barak Shoshany ([email protected]) (http://baraksh.com) | ||
* @version 4.0.0 | ||
* @date 2023-12-27 | ||
* @version 4.0.1 | ||
* @date 2023-12-28 | ||
* @copyright Copyright (c) 2023 Barak Shoshany. Licensed under the MIT license. If you found this project useful, please consider starring it on GitHub! If you use this library in software of any kind, please provide a link to the GitHub repository https://github.com/bshoshany/thread-pool in the source code and documentation. 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) | ||
* | ||
* @brief BS::thread_pool: a fast, lightweight, and easy-to-use C++17 thread pool library. This header file contains independent utility classes that are part of the library, but are not needed to use the thread pool itself. | ||
|
@@ -24,8 +24,10 @@ | |
* @brief A namespace used by Barak Shoshany's projects. | ||
*/ | ||
namespace BS { | ||
// A macro containing the version of the thread pool utilities library. | ||
#define BS_THREAD_POOL_UTILS_VERSION "v4.0.0 (2023-12-27)" | ||
// Macros indicating the version of the thread pool utilities library. | ||
#define BS_THREAD_POOL_UTILS_VERSION_MAJOR 4 | ||
#define BS_THREAD_POOL_UTILS_VERSION_MINOR 0 | ||
#define BS_THREAD_POOL_UTILS_VERSION_PATCH 1 | ||
|
||
/** | ||
* @brief A utility class to allow simple signalling between threads. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
/** | ||
* @file BS_thread_pool_test.cpp | ||
* @author Barak Shoshany ([email protected]) (http://baraksh.com) | ||
* @version 4.0.0 | ||
* @date 2023-12-27 | ||
* @version 4.0.1 | ||
* @date 2023-12-28 | ||
* @copyright Copyright (c) 2023 Barak Shoshany. Licensed under the MIT license. If you found this project useful, please consider starring it on GitHub! If you use this library in software of any kind, please provide a link to the GitHub repository https://github.com/bshoshany/thread-pool in the source code and documentation. 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) | ||
* | ||
* @brief BS::thread_pool: a fast, lightweight, and easy-to-use C++17 thread pool library. This program tests all aspects of the library, but is not needed in order to use the library. | ||
|
@@ -49,6 +49,19 @@ | |
#include "BS_thread_pool.hpp" | ||
#include "BS_thread_pool_utils.hpp" | ||
|
||
// Macros indicating the version of the thread pool test program. | ||
#define BS_THREAD_POOL_TEST_VERSION_MAJOR 4 | ||
#define BS_THREAD_POOL_TEST_VERSION_MINOR 0 | ||
#define BS_THREAD_POOL_TEST_VERSION_PATCH 1 | ||
|
||
#if (BS_THREAD_POOL_TEST_VERSION_MAJOR != BS_THREAD_POOL_VERSION_MAJOR || BS_THREAD_POOL_TEST_VERSION_MINOR != BS_THREAD_POOL_VERSION_MINOR || BS_THREAD_POOL_TEST_VERSION_PATCH != BS_THREAD_POOL_VERSION_PATCH) | ||
#error The versions of BS_thread_pool_test.cpp and BS_thread_pool.hpp do not match. Aborting compilation. | ||
#endif | ||
|
||
#if (BS_THREAD_POOL_TEST_VERSION_MAJOR != BS_THREAD_POOL_UTILS_VERSION_MAJOR || BS_THREAD_POOL_TEST_VERSION_MINOR != BS_THREAD_POOL_UTILS_VERSION_MINOR || BS_THREAD_POOL_TEST_VERSION_PATCH != BS_THREAD_POOL_UTILS_VERSION_PATCH) | ||
#error The versions of BS_thread_pool_test.cpp and BS_thread_pool_utils.hpp do not match. Aborting compilation. | ||
#endif | ||
|
||
using int64 = std::int_fast64_t; | ||
using std::size_t; | ||
|
||
|
@@ -2248,8 +2261,9 @@ void show_intro() | |
dual_println("GitHub: https://github.com/bshoshany/thread-pool"); | ||
dual_println(); | ||
|
||
dual_println("Thread pool library version is ", BS_THREAD_POOL_VERSION, "."); | ||
dual_println("Hardware concurrency is ", std::thread::hardware_concurrency(), "."); | ||
dual_println("Thread pool library version is ", BS_THREAD_POOL_VERSION_MAJOR, '.', BS_THREAD_POOL_VERSION_MINOR, '.', BS_THREAD_POOL_VERSION_PATCH, '.'); | ||
dual_println("Thread pool utilities library version is ", BS_THREAD_POOL_UTILS_VERSION_MAJOR, '.', BS_THREAD_POOL_UTILS_VERSION_MINOR, '.', BS_THREAD_POOL_UTILS_VERSION_PATCH, '.'); | ||
dual_println("Hardware concurrency is ", std::thread::hardware_concurrency(), '.'); | ||
dual_println(); | ||
|
||
dual_print("Native handles are "); | ||
|
@@ -2279,8 +2293,8 @@ void show_intro() | |
|
||
dual_println(); | ||
|
||
dual_println("Detected OS: ", detect_os(), "."); | ||
dual_println("Detected compiler: ", detect_compiler(), "."); | ||
dual_println("Detected OS: ", detect_os(), '.'); | ||
dual_println("Detected compiler: ", detect_compiler(), '.'); | ||
dual_println(); | ||
|
||
dual_println("Important: Please do not run any other applications, especially multithreaded applications, in parallel with this test!"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
# BS_thread_pool_test.ps1 | ||
# By Barak Shoshany ([email protected]) (http://baraksh.com) | ||
# v4.0.0, 2023-12-27 | ||
# v4.0.1, 2023-12-28 | ||
# Copyright (c) 2023 Barak Shoshany. Licensed under the MIT license. If you found this project useful, please consider starring it on GitHub! If you use this library in software of any kind, please provide a link to the GitHub repository https://github.com/bshoshany/thread-pool in the source code and documentation. 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) | ||
# | ||
# BS::thread_pool: a fast, lightweight, and easy-to-use C++17 thread pool library. This script compiles and runs the bundled test program with different compilers. | ||
|
@@ -119,10 +119,10 @@ $ExePrefix = 'BS_thread_pool_test_' | |
|
||
$Executables = @() | ||
|
||
Function Build-ClangGCC([String] $Compiler, [String] $ExeSuffix, [String] $Macros = '') | ||
Function Build-ClangGCC([String] $Compiler, [String] $ExeSuffix, [String] $ExtraFlags = '') | ||
{ | ||
$FullExe = Join-Path $BuildFolder "$ExePrefix$ExeSuffix$Extension" | ||
$Command = "$Compiler $SourceFile$PThread -I../include -std=c++17 -O3 -march=native -Wall -Wextra -Wconversion -Wsign-conversion -Wpedantic -Weffc++ -Wshadow -o $FullExe $Macros" | ||
$Command = "$Compiler $SourceFile$PThread -I../include -std=c++17 -O3 -march=native -Wall -Wextra -Wconversion -Wsign-conversion -Wpedantic -Weffc++ -Wshadow -o $FullExe $ExtraFlags" | ||
Write-Command $Command | ||
Invoke-Expression $Command | ||
If ($LASTEXITCODE) | ||
|
@@ -153,8 +153,8 @@ Write-Host | |
If (Get-Command 'g++' -ErrorAction SilentlyContinue) | ||
{ | ||
Write-Text 'Compiling with GCC...' | ||
Build-ClangGCC 'g++' 'gcc' | ||
Build-ClangGCC 'g++' 'gcc_light' '-DBS_THREAD_POOL_LIGHT_TEST' | ||
Build-ClangGCC 'g++' 'gcc' '-Wuseless-cast' | ||
Build-ClangGCC 'g++' 'gcc_light' '-Wuseless-cast -DBS_THREAD_POOL_LIGHT_TEST' | ||
} | ||
Else | ||
{ | ||
|
@@ -163,12 +163,12 @@ Else | |
|
||
Write-Host | ||
|
||
Function Build-MSVC([String] $ExeSuffix, [String] $Macros = '') | ||
Function Build-MSVC([String] $ExeSuffix, [String] $ExtraFlags = '') | ||
{ | ||
$MSVCName = "$ExePrefix$ExeSuffix" | ||
$FullExe = Join-Path $BuildFolder "$MSVCName$Extension" | ||
$FullObj = Join-Path $BuildFolder "$MSVCName.obj" | ||
$Env:BS_THREAD_POOL_MSVC_COMMAND = "cl $SourceFile /I../include /std:c++17 /permissive- /O2 /W4 /EHsc /Fe:$FullExe /Fo:$FullObj $Macros" | ||
$Env:BS_THREAD_POOL_MSVC_COMMAND = "cl $SourceFile /I../include /std:c++17 /permissive- /O2 /W4 /EHsc /Fe:$FullExe /Fo:$FullObj $ExtraFlags" | ||
Write-Command $Env:BS_THREAD_POOL_MSVC_COMMAND | ||
pwsh -Command { | ||
$CurrentDir = Get-Location | ||
|