Published May 26, 2023
| Version v3.5.0
Software
Open
A C++17 Thread Pool for High-Performance Scientific Computing
Authors/Creators
Description
v3.5.0 (2023-05-25)
BS_thread_pool.hppandBS_thread_pool_light.hpp:- Added a new member function,
purge(), to the full (non-light) thread pool. This function purges all the tasks waiting in the queue. Tasks that are currently running will not be affected, but any tasks still waiting in the queue will be removed and will never be executed by the threads. Please note that there is no way to restore the purged tasks. - Fix a bug which caused
wait_for_tasks()to only block the first thread that called it. Now it blocks every thread that calls it, which is the expected behavior. In addition, all related deadlock have now been completely resolved. This also applies to the variantswait_for_tasks_duration()andwait_for_tasks_until()in the non-light version. See #110.- Note: You should never call
wait_for_tasks()from within a thread of the same thread pool, as that will cause it to wait forever! This fix is relevant for situations whenwait_for_tasks()is called from an auxiliarystd::threador a separate thread pool.
- Note: You should never call
push_task()andsubmit()now avoid creating unnecessary copies of the function object. This should improve performance, especially if large objects are involved. See #90.- Optimized the way condition variables are used by the thread pool class. Shared variables are now modified while owning the mutex, but condition variables are notified after the mutex is released, if possible. See #84.
- Instead of a variable
tasks_totalto keep track of the total number of tasks (queued + running), the thread pool class now uses a variabletasks_runningto keep track only of the number of running tasks, with the number of tasks in the queue obtained viatasks.size(). This makes more sense in terms of the internal logic of the class. - All atomic variables have been converted to non-atomic. They are now all governed by
tasks_mutex, so they do not need to be atomic. This eliminates redundant locking, and may improve performance a bit. runninghas been renamed toworkers_runningandtask_done_cvhas been renamed totasks_done_cv.- The worker now only notifies thi condition variable
tasks_done_cvif all the tasks are done, not just a single task. Checking if the tasks are done is cheaper than notifying the condition variable, so since the worker no longer notifies the condition variable every single time it finishes a task, this should improve performance a bit ifwait_for_tasks()is used.
- Added a new member function,
BS_thread_pool_test.cpp:- Combined the tests for the full and light versions into one program. The file
BS_thread_pool_light_test.cpphas been removed. - The tests for the light version are now much more comprehensive. The only features that are not tested in the light version are those that do not exist in it.
- Added a test for the new
purge()member function. - Added a test to ensure that
push_task()andsubmit()do not create unnecessary copies of the function object. - Added a test to ensure that
push_task()andsubmit()correctly accept arguments passed by value, reference, and constant reference. - Added a test to ensure that
wait_for_tasks()blocks all external threads that call it. _CRT_SECURE_NO_WARNINGSis now set only if it has not already been defined, to prevent errors in MSVC projects which already have it set as part of the default build settings. See #72.
- Combined the tests for the full and light versions into one program. The file
README.md:- Added documentation for the new
purge()member function. - Added an explanation for how to pass arguments by reference or constant reference when submitting functions to the queue, using the wrappers
std::ref()andstd::cref()respectively. See #83. - Added a link to my lecture notes for a course taught at McMaster University, for the benefit of beginner C++ programmers who wish to learn some of the advanced techniques and programming practices used in developing this library.
- Removed the sample test results, since the complete log file (including the deadlock tests) is now over 500 lines long.
- Added documentation for the new
- Other:
- A
.clang-formatfile with the project's formatting conventions is now included in the GitHub repository. The pull request template now asks to format any new code using this file, so that it is consistent with the rest of the library. - A PowerShell script,
BS_thread_pool_test.ps1, is now provided in the GitHub repository to make running the test on multiple compilers and operating systems easier. Since it is written in PowerShell, it is fully portable and works on Windows, Linux, and macOS. The script will automatically detect if Clang, GCC, and/or MSVC are available, compile the test program using each available compiler, and then run each compiled test program 5 times and report on any errors. The pull request template now recommends using this script for testing. - Since the root folder has become a bit crowded, the header files
BS_thread_pool.hppandBS_thread_pool_light.hpphave been moved to theincludesubfolder, and the test fileBS_thread_pool_test.cpphas been moved to thetestssubfolder, which also contains the new test scriptBS_thread_pool_test.ps1.
- A
Notes
Files
bshoshany/thread-pool-v3.5.0.zip
Files
(64.3 kB)
| Name | Size | Download all |
|---|---|---|
|
md5:ac5e2fe37f4842d4aa47d8ff542b5409
|
64.3 kB | Preview Download |
Additional details
Related works
- Is supplement to
- https://github.com/bshoshany/thread-pool/tree/v3.5.0 (URL)