线程池和c ++ 11中的执行队列 [英] Thread pool and execution queue in c++11

查看:304
本文介绍了线程池和c ++ 11中的执行队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆并行任务要完成,但只有几个工作线程(例如8,但我希望这是可配置的)。

I have a bunch of parallel tasks to complete, but only a few worker threads (say 8, but I want this to be configurable).

线程运行,并且每个线程从队列中弹出下一个任务,只要队列有任务。

So, 8 threads run, and each of the threads pops the next task from the queue, as long as the queue has tasks.

C ++ 11提供任何内置 cd>

我看到一些类似的讨论与 std :: async ,但我认为它对编译器的实现太多了。

I see some similar discussions related to std::async, but I think it leaves too much to the implementation of the compiler.

推荐答案

如果你的意思是一个线程池, ++ 11不提供一个,你还必须决定是否要在使用C ++ 11的线程模型中使用原子,互斥或栅栏,如果你正在寻找的东西,将开箱即用的唯一的真实解决方案,AFAIK,是英特尔TBB库。有一个非官方的提升线程池库,但不看起来真的流行或活跃。

If you mean a threading-pool, no C++11 doesn't provide one, you also have to decide if you want to use atomics, mutexes or fences in your threading model with C++11, if you are looking for something that will work out of the box the only real solution, AFAIK, is the Intel TBB library. There is an unofficial boost threading pool library too but doesn't look really popular or active.

这篇关于线程池和c ++ 11中的执行队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆