<small id='wy8IM'></small><noframes id='wy8IM'>

    <bdo id='wy8IM'></bdo><ul id='wy8IM'></ul>

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

    2. <legend id='wy8IM'><style id='wy8IM'><dir id='wy8IM'><q id='wy8IM'></q></dir></style></legend>

        <tfoot id='wy8IM'></tfoot>
      1. stl 向量并发读取线程安全吗?

        Is stl vector concurrent read thread-safe?(stl 向量并发读取线程安全吗?)
      2. <legend id='RnwxU'><style id='RnwxU'><dir id='RnwxU'><q id='RnwxU'></q></dir></style></legend>

          <tfoot id='RnwxU'></tfoot>

            <tbody id='RnwxU'></tbody>
          • <small id='RnwxU'></small><noframes id='RnwxU'>

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

                1. 本文介绍了stl 向量并发读取线程安全吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在开发一个应用程序,在该应用程序中,需要大量线程迭代一组字符串值,并尝试将其自己的数据与列表中的可用数据进行匹配.

                  我正在寻找以下用例:

                  1. Vector 被初始化为 std::string 类型的几个元素.(假设对象名称是 strList).strList 将在应用程序启动时初始化.
                  2. 所有线程将遍历 strList 以查看它的值是否与 strList 的至少一个元素匹配.
                  3. 任何线程都不会尝试修改 strList,它会被严格用作只读对象.

                  所以你能告诉我并发读取在向量对象上是否是线程安全的.我使用的是 RHEL 6,gcc 版本是 4.5.x

                  解决方案

                  YES 对于您提到的场景,它是完全线程安全的.

                  <小时>

                  实际上,STL 并不是一个正确的引用方式.
                  它是 C++ 标准库.

                  C++03 标准根本不讨论并发性,因此并发性方面被省略为编译器的实现细节.因此,您应该在编译器附带的文档中寻找与并发相关的答案.

                  大多数 STL 实现不是线程安全的.
                  但是对于来自多个线程的同一对象的并发读取,大多数 STL 实现确实是线程安全的.

                  参考:

                  MSDN 说:<块引用>

                  单个对象对于从多个线程读取是线程安全的.例如,给定一个对象 A,同时从线程 1 和线程 2 读取 A 是安全的.

                  Dinkumware STL 文档 说:

                  <块引用>

                  多个线程可以安全地读取同一个容器对象.(容器对象中有不受保护的可变子对象.)

                  GCC 文档 说:

                  我们目前使用 SGI STL 定义线程安全,其中指出:

                  <块引用>

                  STL 的 SGI 实现是线程安全的,仅在对不同容器的同时访问是安全的,对共享容器的同时读取访问是安全的意义上.如果多个线程访问单个容器,并且至少有一个线程可能会写入,则用户有责任确保容器访问期间线程之间的互斥.

                  所以从上面可以看出,在 GCC 中从多个线程并发读取同一个对象是线程安全的.

                  注意:GCC 的标准库是 SGI 的 STL 代码的衍生物.

                  I am working on a application where huge number of threads are expected to iterate over set of string values and try to match it's own data with the data available in the list.

                  I am looking for following use case:

                  1. Vector is initialized with few elements of type std::string. (Lets say object name is strList). strList will get initialized at the time of application startup.
                  2. All threads will iterate over strList to see if it's value matches with atleast one element of strList.
                  3. No thread will ever try to modify strList and it will be strictly used as readonly object.

                  So could you please tell me if concurrent reads are thread-safe on vector object. I am using RHEL 6 and gcc version is 4.5.x

                  解决方案

                  YES for the scenario you mention, it is perfectly Thread Safe.


                  Actually, STL is not a correct way of referring it.
                  It is the C++ Standard Library.

                  The C++03 Standard does not talk about concurrency at all, So the concurrency aspect is left out as an implementation detail for compilers. So the documentation that comes with your compiler is where one should look to for answers related to concurrency.

                  Most of the STL implementations are not thread safe as such.
                  But for concurrent reads of same object from multiple threads most implementations of STL are indeed thread safe.

                  References:

                  MSDN says:

                  A single object is thread safe for reading from multiple threads. For example, given an object A, it is safe to read A from thread 1 and from thread 2 simultaneously.

                  The Dinkumware STL-Documentation says:

                  Multiple threads can safely read the same container object. (There are nunprotected mutable subobjects within a container object.)

                  GCC Documentation says:

                  We currently use the SGI STL definition of thread safety, which states:

                  The SGI implementation of STL is thread-safe only in the sense that simultaneous accesses to distinct containers are safe, and simultaneous read accesses to to shared containers are safe. If multiple threads access a single container, and at least one thread may potentially write, then the user is responsible for ensuring mutual exclusion between the threads during the container accesses.

                  So from the above, Yes it is thread safe in GCC to have concurrent reads of same object from multiple threads.

                  Note: GCC's Standard Library is a derivative of SGI's STL code.

                  这篇关于stl 向量并发读取线程安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                  How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                  Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                  Delay Loading DLLs(延迟加载 DLL)
                  Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                  Loading a dll from a dll?(从 dll 加载 dll?)
                      <tbody id='Jc5Rf'></tbody>

                    <legend id='Jc5Rf'><style id='Jc5Rf'><dir id='Jc5Rf'><q id='Jc5Rf'></q></dir></style></legend>

                    <tfoot id='Jc5Rf'></tfoot>

                    <small id='Jc5Rf'></small><noframes id='Jc5Rf'>

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