[res.on.data.races]

# 16 Library introduction [[library]](./#library)

## 16.4 Library-wide requirements [[requirements]](requirements#res.on.data.races)

### 16.4.6 Conforming implementations [[conforming]](conforming#res.on.data.races)

#### 16.4.6.10 Data race avoidance [res.on.data.races]

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3769)

This subclause specifies requirements that implementations shall meet to prevent[data races](intro.multithread#def:data_race "6.10.2 Multi-threaded executions and data races [intro.multithread]")[.](#1.sentence-1)

Every standard library function shall meet each requirement unless otherwise specified[.](#1.sentence-2)

Implementations may prevent data races in cases other than those specified below[.](#1.sentence-3)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3775)

A C++ standard library function shall not directly or indirectly access
objects ([[intro.multithread]](intro.multithread "6.10.2 Multi-threaded executions and data races")) accessible by threads other than the current thread
unless the objects are accessed directly or indirectly via the function's arguments,
including this[.](#2.sentence-1)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3781)

A C++ standard library function shall not directly or indirectly modify
objects ([[intro.multithread]](intro.multithread "6.10.2 Multi-threaded executions and data races")) 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[.](#3.sentence-1)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3787)

[*Note [1](#note-1)*:

This means, for example, that implementations can't use an object with static storage duration for
internal purposes without synchronization because doing so can cause a data race even in
programs that do not explicitly share objects between threads[.](#4.sentence-1)

â *end note*]

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3794)

A C++ standard library function shall not access objects indirectly accessible via its
arguments or via elements of its container arguments except by invoking functions
required by its specification on those container elements[.](#5.sentence-1)

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3799)

Operations on iterators obtained by calling a standard library container or string
member function may access the underlying container, but shall not modify it[.](#6.sentence-1)

[*Note [2](#note-2)*:

In particular, container operations that invalidate iterators conflict
with operations on iterators associated with that container[.](#6.sentence-2)

â *end note*]

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3807)

Implementations may share their own internal objects between threads if the objects are
not visible to users and are protected against data races[.](#7.sentence-1)

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3811)

Unless otherwise specified, C++ standard library functions shall perform all operations
solely within the current thread if those operations have effects that are[visible](intro.multithread#def:side_effects,visible "6.10.2 Multi-threaded executions and data races [intro.multithread]") to users[.](#8.sentence-1)

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3816)

[*Note [3](#note-3)*:

This allows implementations to parallelize operations if there are no visibleside effects[.](#9.sentence-1)

â *end note*]
