问题描述
是否可以使用 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 创建线程池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!