A few minor upgrades update of ThreadPool.h #120
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
1.使用std::invoke_result替代std::result_of
std::result_of已被C++17中的std::invoke_result取代,前者在C++20中被弃用。为了保证代码的现代性和兼容性,使用了std::invoke_result。
2.捕获和处理任务中的异常
当前实现中,如果任务抛出异常,可能导致线程终止。所以我尝试在任务执行时捕获异常,并提供相应的处理机制。
3.增加线程池状态查询功能
增加了一些方法,可以查询线程池的状态,例如:当前活跃线程数、任务队列长度等,便于调试和监控。