• <small id='Hw0kc'></small><noframes id='Hw0kc'>

      <bdo id='Hw0kc'></bdo><ul id='Hw0kc'></ul>
    <legend id='Hw0kc'><style id='Hw0kc'><dir id='Hw0kc'><q id='Hw0kc'></q></dir></style></legend>

    <tfoot id='Hw0kc'></tfoot>
    1. <i id='Hw0kc'><tr id='Hw0kc'><dt id='Hw0kc'><q id='Hw0kc'><span id='Hw0kc'><b id='Hw0kc'><form id='Hw0kc'><ins id='Hw0kc'></ins><ul id='Hw0kc'></ul><sub id='Hw0kc'></sub></form><legend id='Hw0kc'></legend><bdo id='Hw0kc'><pre id='Hw0kc'><center id='Hw0kc'></center></pre></bdo></b><th id='Hw0kc'></th></span></q></dt></tr></i><div id='Hw0kc'><tfoot id='Hw0kc'></tfoot><dl id='Hw0kc'><fieldset id='Hw0kc'></fieldset></dl></div>

      1. C++11 中是否有并发容器?

        时间:2023-05-23

        1. <tfoot id='iAb8H'></tfoot>
            <bdo id='iAb8H'></bdo><ul id='iAb8H'></ul>
            <i id='iAb8H'><tr id='iAb8H'><dt id='iAb8H'><q id='iAb8H'><span id='iAb8H'><b id='iAb8H'><form id='iAb8H'><ins id='iAb8H'></ins><ul id='iAb8H'></ul><sub id='iAb8H'></sub></form><legend id='iAb8H'></legend><bdo id='iAb8H'><pre id='iAb8H'><center id='iAb8H'></center></pre></bdo></b><th id='iAb8H'></th></span></q></dt></tr></i><div id='iAb8H'><tfoot id='iAb8H'></tfoot><dl id='iAb8H'><fieldset id='iAb8H'></fieldset></dl></div>
            • <small id='iAb8H'></small><noframes id='iAb8H'>

                <legend id='iAb8H'><style id='iAb8H'><dir id='iAb8H'><q id='iAb8H'></q></dir></style></legend>
                    <tbody id='iAb8H'></tbody>

                  本文介绍了C++11 中是否有并发容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  特别是,我正在寻找阻塞队列.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:

                  • concurrent_vector Class 是一个序列容器类,允许随机访问任何元素.它支持并发安全的追加、元素访问、迭代器访问和迭代器遍历操作.
                  • concurrent_queue Class 是一个序列容器类,它允许首先-in, first-out 访问其元素.它支持一组有限的并发安全操作,例如 push 和 try_pop,仅举几例.
                  • The concurrent_vector Class is a sequence container class that allows random access to any element. It enables concurrency-safe append, element access, iterator access and iterator traversal operations.
                  • The concurrent_queue Class is a sequence container class that allows first-in, first-out access to its elements. It enables a limited set of concurrency-safe operations, such as push and try_pop, to name a few.

                  一些示例此处.

                  也很有趣:http://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html.

                  这篇关于C++11 中是否有并发容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:精确的时间测量 下一篇:如何编写出现在 Intellisense 中的 C++ 注释?

                  相关文章

                  最新文章

                  <tfoot id='Ro2Ra'></tfoot>
                1. <small id='Ro2Ra'></small><noframes id='Ro2Ra'>

                2. <i id='Ro2Ra'><tr id='Ro2Ra'><dt id='Ro2Ra'><q id='Ro2Ra'><span id='Ro2Ra'><b id='Ro2Ra'><form id='Ro2Ra'><ins id='Ro2Ra'></ins><ul id='Ro2Ra'></ul><sub id='Ro2Ra'></sub></form><legend id='Ro2Ra'></legend><bdo id='Ro2Ra'><pre id='Ro2Ra'><center id='Ro2Ra'></center></pre></bdo></b><th id='Ro2Ra'></th></span></q></dt></tr></i><div id='Ro2Ra'><tfoot id='Ro2Ra'></tfoot><dl id='Ro2Ra'><fieldset id='Ro2Ra'></fieldset></dl></div>
                    <bdo id='Ro2Ra'></bdo><ul id='Ro2Ra'></ul>

                    1. <legend id='Ro2Ra'><style id='Ro2Ra'><dir id='Ro2Ra'><q id='Ro2Ra'></q></dir></style></legend>