Skip to content

Commit dd35f66

Browse files
committed
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.
1 parent 2f334a1 commit dd35f66

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

libstdc++-v3/doc/html/manual/using_concurrency.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@
126126
the container the iterator refers to (for example incrementing a
127127
list iterator must access the pointers between nodes, which are part
128128
of the container and so conflict with other accesses to the container).
129+
</p><p>
130+
The Copy-On-Write <code class="classname">std::string</code> implementation
131+
used before GCC 5 (and with
132+
<a class="link" href="using_dual_abi.html" title="Dual ABI">_GLIBCXX_USE_CXX11_ABI=0</a>)
133+
is not a standard container and does not conform to the data race
134+
avoidance rules described above. For the Copy-On-Write
135+
<code class="classname">std::string</code>, non-const member functions such as
136+
<code class="function">begin()</code> are considered to be modifying accesses
137+
and so must not be used concurrently with any other accesses to the
138+
same object.
129139
</p><p>Programs which follow the rules above will not encounter data
130140
races in library code, even when using library types which share
131141
state between distinct objects. In the example below the

libstdc++-v3/doc/xml/manual/using.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,6 +2069,18 @@ gcc version 4.1.2 20070925 (Red Hat 4.1.2-33)
20692069
of the container and so conflict with other accesses to the container).
20702070
</para>
20712071

2072+
<para>
2073+
The Copy-On-Write <classname>std::string</classname> implementation
2074+
used before GCC 5 (and with
2075+
<link linkend="manual.intro.using.abi">_GLIBCXX_USE_CXX11_ABI=0</link>)
2076+
is not a standard container and does not conform to the data race
2077+
avoidance rules described above. For the Copy-On-Write
2078+
<classname>std::string</classname>, non-const member functions such as
2079+
<function>begin()</function> are considered to be modifying accesses
2080+
and so must not be used concurrently with any other accesses to the
2081+
same object.
2082+
</para>
2083+
20722084
<para>Programs which follow the rules above will not encounter data
20732085
races in library code, even when using library types which share
20742086
state between distinct objects. In the example below the

0 commit comments

Comments
 (0)