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 创建线程池
基础教程推荐
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- c++ STL设置差异 2022-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
