This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of Resolved status.

1329. Data races on vector<bool>

Section: 21.2.2 [container.requirements.dataraces] Status: Resolved Submitter: Jeffrey Yaskin Opened: 2010-03-09 Last modified: 2016-12-23

Priority: Not Prioritized

View all other issues in [container.requirements.dataraces].

View all issues with Resolved status.


The common implementation of vector<bool> is as an unsynchronized bitfield. The addition of 21.2.2 [container.requirements.dataraces]/2 would require either a change in representation or a change in access synchronization, both of which are undesireable with respect to compatibility and performance.

[ 2010 Pittsburgh: Moved to NAD EditorialResolved. Rationale added below. ]


Solved by N3069.

Proposed resolution:

Container data races 21.2.2 [container.requirements.dataraces]

Paragraph 1 is unchanged as follows:

1 For purposes of avoiding data races (, implementations shall consider the following functions to be const: begin, end, rbegin, rend, front, back, data, find, lower_bound, upper_bound, equal_range, and, except in associative containers, operator[].

Edit paragraph 2 as follows:

2 Notwithstanding (, implementations are required to avoid data races when the contents of the contained object in different elements in the same sequence, excepting vector<bool>, are modified concurrently.

Edit paragraph 3 as follows:

3 [Note: For a vector<int> x with a size greater than one, x[1] = 5 and *x.begin() = 10 can be executed concurrently without a data race, but x[0] = 5 and *x.begin() = 10 executed concurrently may result in a data race. As an exception to the general rule, for a vector<bool> y, y[i] = true may race with y[j] = true.end note]