新增全局线程池, 更新线程池注释
This commit is contained in:
parent
c59daeaa92
commit
3d811d3b20
@ -11,11 +11,34 @@
|
||||
#include "containers/safe_vector.h"
|
||||
|
||||
class queued_thread_pool {
|
||||
|
||||
public:
|
||||
explicit queued_thread_pool(size_t num_threads = std::thread::hardware_concurrency());
|
||||
/**
|
||||
* @brief 创建一个线程池
|
||||
* @param num_threads 线程池中线程的数量, 默认为 CPU 核心数减 1, 避免主线程被占用
|
||||
*/
|
||||
explicit queued_thread_pool(size_t num_threads = std::thread::hardware_concurrency() - 1);
|
||||
~queued_thread_pool();
|
||||
|
||||
/**
|
||||
* @brief 获取全局线程池
|
||||
* @return 全局线程池
|
||||
*/
|
||||
static queued_thread_pool& global() {
|
||||
static queued_thread_pool instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 提交一个任务到线程池
|
||||
* @tparam F 任务函数类型
|
||||
* @tparam Args 任务函数参数类型
|
||||
* @param in_func 任务函数
|
||||
* @param in_args 任务函数参数
|
||||
* @return 任务的 std::future 对象
|
||||
* @code
|
||||
* auto res = thread_pool.submit([](int a, int b) { return a + b; }, 1, 2);
|
||||
* @endcode
|
||||
*/
|
||||
template<typename F, typename... Args>
|
||||
auto submit(F&& in_func, Args&&... in_args) {
|
||||
using return_type = std::invoke_result_t<F, Args...>;
|
||||
|
Loading…
x
Reference in New Issue
Block a user