diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2025-04-11 11:08:34 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2025-04-14 13:13:11 +0100 |
commit | dd35f66287b7cca196a720c9641e463255dceb1c (patch) | |
tree | 6c50820bb98d7c2c6543b964ce419cbbdc9d2ffc | |
parent | 2f334a10bce0409c2cb4616496aafcb78f7db3d8 (diff) | |
download | gcc-dd35f66287b7cca196a720c9641e463255dceb1c.zip gcc-dd35f66287b7cca196a720c9641e463255dceb1c.tar.gz gcc-dd35f66287b7cca196a720c9641e463255dceb1c.tar.bz2 |
libstdc++: Document thread-safety for COW std::string [PR21334]
The gcc4-compatible copy-on-write std::string does not conform to the
C++11 requirements on data race avoidance in standard containers.
Specifically, calling non-const member functions such as begin() and
data() needs to do the "copy on write" operation and so is most
definitely a modification of the object. As such, those non-const
members must not be called concurrently with any other uses of the
string object.
libstdc++-v3/ChangeLog:
PR libstdc++/21334
* doc/xml/manual/using.xml: Document that container data race
avoidance rules do not apply to COW std::string.
* doc/html/*: Regenerate.
-rw-r--r-- | libstdc++-v3/doc/html/manual/using_concurrency.html | 10 | ||||
-rw-r--r-- | libstdc++-v3/doc/xml/manual/using.xml | 12 |
2 files changed, 22 insertions, 0 deletions
diff --git a/libstdc++-v3/doc/html/manual/using_concurrency.html b/libstdc++-v3/doc/html/manual/using_concurrency.html index d21f158..d570d3a 100644 --- a/libstdc++-v3/doc/html/manual/using_concurrency.html +++ b/libstdc++-v3/doc/html/manual/using_concurrency.html @@ -126,6 +126,16 @@ gcc version 4.1.2 20070925 (Red Hat 4.1.2-33) the container the iterator refers to (for example incrementing a list iterator must access the pointers between nodes, which are part of the container and so conflict with other accesses to the container). + </p><p> + The Copy-On-Write <code class="classname">std::string</code> implementation + used before GCC 5 (and with + <a class="link" href="using_dual_abi.html" title="Dual ABI">_GLIBCXX_USE_CXX11_ABI=0</a>) + is not a standard container and does not conform to the data race + avoidance rules described above. For the Copy-On-Write + <code class="classname">std::string</code>, non-const member functions such as + <code class="function">begin()</code> are considered to be modifying accesses + and so must not be used concurrently with any other accesses to the + same object. </p><p>Programs which follow the rules above will not encounter data races in library code, even when using library types which share state between distinct objects. In the example below the diff --git a/libstdc++-v3/doc/xml/manual/using.xml b/libstdc++-v3/doc/xml/manual/using.xml index 7ca3a3f..bf92c49 100644 --- a/libstdc++-v3/doc/xml/manual/using.xml +++ b/libstdc++-v3/doc/xml/manual/using.xml @@ -2069,6 +2069,18 @@ gcc version 4.1.2 20070925 (Red Hat 4.1.2-33) of the container and so conflict with other accesses to the container). </para> + <para> + The Copy-On-Write <classname>std::string</classname> implementation + used before GCC 5 (and with + <link linkend="manual.intro.using.abi">_GLIBCXX_USE_CXX11_ABI=0</link>) + is not a standard container and does not conform to the data race + avoidance rules described above. For the Copy-On-Write + <classname>std::string</classname>, non-const member functions such as + <function>begin()</function> are considered to be modifying accesses + and so must not be used concurrently with any other accesses to the + same object. + </para> + <para>Programs which follow the rules above will not encounter data races in library code, even when using library types which share state between distinct objects. In the example below the |