特别是,我正在寻找阻塞队列.C ++ 11中有这样的东西吗?如果没有,我的其他选择是什么?我真的不想再深入到线程级别了.太容易出错了.
In particular, I am looking for a blocking queue. Is there such a thing in C++11? If not, what are my other options? I really don't want to go down to the thread level myself anymore. Way too error-prone.
根据 Diego Dagum来自 Microsoft 的 Visual C++ 团队:
一个反复出现的问题(好吧,其中之一)是关于 STL 容器的以及它们是否是线程安全的.
A recurrent question (well, one of the many) is about STL containers and whether they are thread safe.
在这里用 Stephan 的话来说,事实是它们不是,不是作为bug 但作为一个特性:拥有每个 STL 的每个成员函数容器获取内部锁会破坏性能.作为一个通用的、高度可重用的库,它实际上不会提供正确性之一:放置锁的正确级别是由程序在做什么决定.从这个意义上说,个人成员函数往往不是那么正确的级别.
Taking Stephan’s words here, the reality is that they aren’t, not as a bug but as a feature: having every member function of every STL container acquiring an internal lock would annihilate performance. As a general purpose, highly reusable library, it wouldn’t actually provide correctness either: the correct level to place locks is determined by what the program is doing. In that sense, individual member functions don’t tend to be such correct level.
并行模式库 (PPL) 包括几个容器提供对其元素的线程安全访问:
The Parallel Patterns Library (PPL) includes several containers that provide thread-safe access to their elements:
一些示例此处.
也很有趣:http://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html.
这篇关于C++11 中是否有并发容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
为什么两个函数的地址相同?Why do two functions have the same address?(为什么两个函数的地址相同?)
为什么 std::function 的初始化程序必须是可复制构Why the initializer of std::function has to be CopyConstructible?(为什么 std::function 的初始化程序必须是可复制构造的?)
混合模板与多态性mixing templates with polymorphism(混合模板与多态性)
我什么时候应该使用关键字“typename"?使用模When should I use the keyword quot;typenamequot; when using templates(我什么时候应该使用关键字“typename?使用模板时)
依赖名称解析命名空间 std/标准库Dependent name resolution amp; namespace std / Standard Library(依赖名称解析命名空间 std/标准库)
gcc 可以编译可变参数模板,而 clang 不能gcc can compile a variadic template while clang cannot(gcc 可以编译可变参数模板,而 clang 不能)