Creating a thread pool using boost(使用 boost 创建线程池)
问题描述
是否可以使用 boost 的线程创建线程池?我正在查看 boost 的所有库,但找不到线程池管理器(或类似的东西)...有办法吗?
Is it possible to create a thread pool using boost's thread? i was looking all over boost's libs and I couldn't find a thread pool manager (or something like that)... Is there a way to do it?
tnx!
推荐答案
有一个非官方的(尚未)threadpool 在提升中.但是自己实现一个不是问题,特别是如果很好的通用性不是主要目标.想法:您的线程池可以使用 TaskType 类型和工作人员数量进行参数化.必须为 TP 提供采用 TaskType 的处理函数.TP 包含一个添加任务的队列.真正的线程函数只是从队列中获取一个任务并调用传递的处理程序.类似的东西.
There is an unofficial (yet) threadpool in boost. But it's not a problem to implement one yourself especially if great genericity is not a primary goal. Idea: your threadpool can be parametrized with TaskType type and the number of workers. The TP must be given the handler function which takes TaskType. TP contains a queue of added tasks. The real thread function just takes a task from the queue and calls the passed handler. Something like that.
这篇关于使用 boost 创建线程池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 boost 创建线程池


- 近似搜索的工作原理 2021-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 静态初始化顺序失败 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 从python回调到c++的选项 2022-11-16
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- C++ 协变模板 2021-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01