Skip to content

Commit

Permalink
Updated to v4.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
bshoshany committed Dec 28, 2023
1 parent ff95929 commit 6790920
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 40 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Website: <https://baraksh.com/>\
GitHub: <https://github.com/bshoshany>

* [Version history](#version-history)
* [v4.0.1 (2023-12-28)](#v401-2023-12-28)
* [v4.0.0 (2023-12-27)](#v400-2023-12-27)
* [v3.5.0 (2023-05-25)](#v350-2023-05-25)
* [v3.4.0 (2023-05-12)](#v340-2023-05-12)
Expand All @@ -27,6 +28,12 @@ GitHub: <https://github.com/bshoshany>

## Version history

### v4.0.1 (2023-12-28)

* Fixed linkage issue caused by the global variables `BS::this_thread::get_index` and `BS::this_thread::get_pool` not being defined as `inline`. See [134](https://github.com/bshoshany/thread-pool/issues/134) and [137](https://github.com/bshoshany/thread-pool/issues/137).
* Fixed redundant cast in the `BS::thread_pool::blocks` class, and added `-Wuseless-cast` to the GCC warning flags in `BS_thread_pool_test.ps1` to catch similar issues in the future. See [133](https://github.com/bshoshany/thread-pool/pull/133).
* Each of the three files `BS_thread_pool_test.cpp`, `BS_thread_pool.hpp`, and `BS_thread_pool_utils.hpp` now contains three macros indicating the major, minor, and patch version of the file. In addition, `BS_thread_pool_test.cpp` now checks whether the versions of all three files match, and aborts compilation if they do not.

### v4.0.0 (2023-12-27)

* A major new release with numerous changes, additions, fixes, and improvements. Many frequently requested features have been added, and performance has been optimized. Please note that code written using previous releases will need to be modified to work with the new release. The changes needed to migrate to the new API are explicitly indicated below for your convenience.
Expand Down
42 changes: 27 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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);
}
```
Expand Down Expand Up @@ -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.
Expand All @@ -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)
```
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 10 additions & 8 deletions include/BS_thread_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;

Expand Down Expand Up @@ -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

/**
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 6 additions & 4 deletions include/BS_thread_pool_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
26 changes: 20 additions & 6 deletions tests/BS_thread_pool_test.cpp
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.
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 ");
Expand Down Expand Up @@ -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!");
Expand Down
14 changes: 7 additions & 7 deletions tests/BS_thread_pool_test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
{
Expand All @@ -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
Expand Down

0 comments on commit 6790920

Please sign in to comment.