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 创建线程池


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