C++ Thread Pool(C++ 线程池)
问题描述
在生产代码中使用 C++ 的线程池的好的开源实现是什么(类似于 boost)?
What is a good open source implementation of a thread pool for C++ to use in production code (something like boost)?
请提供您自己的示例代码或示例代码用法的链接.
Please provide either your own example code or a link to example code usage.
推荐答案
我认为它仍然不被 Boost 接受,但是一个很好的起点:线程池.一些用法示例,来自网站:
I think it is still not accepted into Boost, but a good staring point: threadpool. Some example of usage, from the web site:
#include "threadpool.hpp"
using namespace boost::threadpool;
// Some example tasks
void first_task()
{
...
}
void second_task()
{
...
}
void third_task()
{
...
}
void execute_with_threadpool()
{
// Create a thread pool.
pool tp(2);
// Add some tasks to the pool.
tp.schedule(&first_task);
tp.schedule(&second_task);
tp.schedule(&third_task);
// Leave this function and wait until all tasks are finished.
}
池的参数2"表示线程数.在这种情况下,tp
的销毁等待所有线程完成.
The argument "2" to the pool indicates the number of threads. In this case, the destruction of tp
waits for all threads to finish.
这篇关于C++ 线程池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++ 线程池


基础教程推荐
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 这个宏可以转换成函数吗? 2022-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01