Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>YES</strong> for the scenario you mention, it is perfectly Thread Safe.</p> <hr> <p>Actually, STL is not a correct way of referring it.<br> It is the <strong><a href="https://stackoverflow.com/questions/5205491/whats-this-stl-vs-c-standard-library-fight-all-about/">C++ Standard Library</a></strong>.</p> <p>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. </p> <p>Most of the STL implementations are <strong>not</strong> thread safe as such.<br> But for concurrent reads of same object from multiple threads most implementations of STL are indeed thread safe. </p> <p><strong>References:</strong></p> <p><strong><a href="http://msdn.microsoft.com/en-us/library/c9ceah3b.aspx" rel="noreferrer">MSDN</a></strong> says: </p> <blockquote> <p>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.</p> </blockquote> <p><strong>The Dinkumware STL-Documentation</strong> says: </p> <blockquote> <p>Multiple threads can safely read the same container object. (There are nunprotected mutable subobjects within a container object.)</p> </blockquote> <p><strong><a href="http://gcc.gnu.org/onlinedocs/libstdc++/manual/using_concurrency.html" rel="noreferrer">GCC Documentation</a></strong> says: </p> <p>We currently use the <strong><a href="http://www.sgi.com/tech/stl/thread_safety.html" rel="noreferrer">SGI STL</a></strong> definition of thread safety, which states: </p> <blockquote> <p>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. <strong>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.</strong></p> </blockquote> <p>So from the above, Yes it is thread safe in GCC to have concurrent reads of same object from multiple threads.</p> <p>Note: GCC's Standard Library is a derivative of SGI's STL code.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload