mirror of
https://github.com/bshoshany/thread-pool.git
synced 2026-07-21 19:13:00 +04:00
5.8 KiB
5.8 KiB
A C++17 Thread Pool for High-Performance Scientific Computing
Version history
- v1.8 (2021-07-28)
- The version history has become too long to be included in
README.md, so I moved it to a separate file,CHANGELOG.md. - A button to open this repository directly in Visual Studio Code has been added to the badges in
README.md. - An internal variable named
promisehas been renamed totask_promiseto avoid any potential errors in case the user invokesusing namespace std. submit()now catches exceptions thrown by the submitted task and forwards them to the future. See this issue.- Eliminated compiler warnings that appeared when using the
-Weffc++flag in GCC. See this pull request.
- The version history has become too long to be included in
- v1.7 (2021-06-02)
- Fixed a bug in
parallelize_loop()which prevented it from actually running loops in parallel, see this issue.
- Fixed a bug in
- v1.6 (2021-05-26)
- Since MSVC does not interpret
andas&&by default, the previous release did not compile with MSVC unless the/permissive-or/Zacompiler 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.
- Since MSVC does not interpret
- v1.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.
- 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
- v1.4 (2021-05-05)
- Added three new public member functions to monitor the tasks submitted to the pool:
get_tasks_queued()gets the number of tasks currently waiting in the queue to be executed by the threads.get_tasks_running()gets the number of tasks currently being executed by the threads.get_tasks_total()gets the total number of unfinished tasks - either still in the queue, or running in a thread.- Note that
get_tasks_running() == get_tasks_total() - get_tasks_queued(). - Renamed the private member variable
tasks_waitingtotasks_totalto make its purpose clearer.
- Added an option to temporarily pause the workers:
- When public member variable
pausedis set totrue, the workers temporarily stop popping new tasks out of the queue, although any tasks already executed will keep running until they are done. Set tofalseagain to resume popping tasks. - While the workers are paused,
wait_for_tasks()will wait for the running tasks instead of all tasks (otherwise it would wait forever). - By utilizing the new pausing mechanism,
reset()can now change the number of threads on-the-fly while there are still tasks waiting in the queue. The new thread pool will resume executing tasks from the queue once it is created.
- When public member variable
parallelize_loop()andwait_for_tasks()now have the same behavior as the worker function with regards to waiting for tasks to complete. If the relevant tasks are not yet complete, then before checking again, they will sleep forsleep_durationmicroseconds, unless that variable is set to zero, in which case they will callstd::this_thread::yield(). This should improve performance and reduce CPU usage.- Merged this commit: Fixed weird error when using MSVC and including
windows.h. - The
README.mdfile has been reorganized and expanded.
- Added three new public member functions to monitor the tasks submitted to the pool:
- v1.3 (2021-05-03)
- Fixed this issue: Removed
std::movefrom thereturnstatement inpush_task(). This previously generated a-Wpessimizing-movewarning in Clang. The assembly code generated by the compiler seems to be the same before and after this change, presumably because the compiler eliminates thestd::moveautomatically, but this change gets rid of the Clang warning. - Fixed this issue: Removed a debugging message printed to
std::cout, which was left in the code by mistake. - Fixed this issue:
parallelize_loop()no longer sends references for the variablesstartandstopwhen callingpush_task(), which may lead to undefined behavior. - A companion paper is now published at arXiv:2105.00613, including additional information such as performance tests on systems with up to 80 hardware threads. The
README.mdhas been updated, and it is now roughly identical in content to the paper.
- Fixed this issue: Removed
- v1.2 (2021-04-29)
- The worker function, which controls the execution of tasks by each thread, now sleeps by default instead of yielding. Previously, when the worker could not find any tasks in the queue, it called
std::this_thread::yield()and then tried again. However, this caused the workers to have high CPU usage when idle, as reported by some users. Now, when the worker function cannot find a task to run, it instead sleeps for a duration given by the public member variablesleep_duration(in microseconds) before checking the queue again. The default value is1000microseconds, which I found to be optimal in terms of both CPU usage and performance, but your own optimal value may be different. - If the constructor is called with an argument of zero for the number of threads, then the default value,
std::thread::hardware_concurrency(), is used instead. - Added a simple helper class,
timer, which can be used to measure execution time for benchmarking purposes. - Improved and expanded the documentation.
- The worker function, which controls the execution of tasks by each thread, now sleeps by default instead of yielding. Previously, when the worker could not find any tasks in the queue, it called
- v1.1 (2021-04-24)
- Cosmetic changes only. Fixed a typo in the Doxygen comments and added a link to the GitHub repository.
- v1.0 (2021-01-15)
- Initial release.