Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There is a specific mention in the C++0x FDIS (n3290) for this.</p> <blockquote> <p><strong>§ 17.6.5.9 Data race avoidance</strong></p> </blockquote> <p>The whole paragraph is of interest but more particularly:</p> <blockquote> <p><em>3/</em> A C++ standard library function shall not directly or indirectly modify objects (1.10) accessible by threads other than the current thread unless the objects are accessed directly or indirectly via the function’s non-const arguments, including this.</p> </blockquote> <p>means that you may call <code>cbegin</code> and <code>cend</code> on <code>std::vector&lt;T&gt;</code> safely. As well as calling <code>operator==</code> or <code>operator&lt;</code> on <code>std::string</code>.</p> <blockquote> <p><em>6/</em> Operations on iterators obtained by calling a standard library container or string member function may access the underlying container, but shall not modify it.</p> </blockquote> <p>means that merely iterating over a container should not modify the said container in any way.</p> <p>Despite <em>3/</em> though, there seems to be room for global objects though, as iterators modifying some kind of shared register object in which they would associate themselves with the container (STL debug features). I don't make sense of:</p> <blockquote> <p><em>7/</em> Implementations may share their own internal objects between threads if the objects are not visible to users and are protected against data races.</p> </blockquote> <p>otherwise.</p> <p>Anyway, the Standard guarantees that iterating over the <code>vector</code> will be safe... but makes no guarantees when it comes to actually reading the objects (those are your own). In this case, this is covered because <code>std::string</code> is covered above.</p> <p><strong>EDIT:</strong> As David Hammen justly noted, this Standard is not yet fully implemented. Many compilers already provided the guarantees above, even though the previous Standard never spoke about threads. MSVC, gcc, clang, icc, comeau, etc... All big names should already provide this guarantee, as can be seen from Als' answer.</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