<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1329: Data races on vector&lt;bool&gt;</title>
<meta property="og:title" content="Issue 1329: Data races on vector&lt;bool&gt;">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1329.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#Resolved">Resolved</a> status.</em></p>
<h3 id="1329"><a href="lwg-defects.html#1329">1329</a>. Data races on <code>vector&lt;bool&gt;</code></h3>
<p><b>Section:</b> 23.2.3 <a href="https://wg21.link/container.requirements.dataraces">[container.requirements.dataraces]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Jeffrey Yaskin <b>Opened:</b> 2010-03-09 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#container.requirements.dataraces">issues</a> in [container.requirements.dataraces].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p>
The common implementation of <code>vector&lt;bool&gt;</code> is as an
unsynchronized bitfield.  The addition of 23.2.3 <a href="https://wg21.link/container.requirements.dataraces">[container.requirements.dataraces]</a>/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.
</p>

<p><i>[
2010 Pittsburgh:  Moved to <del>NAD Editorial</del><ins>Resolved</ins>. Rationale added below.
]</i></p>




<p><b>Rationale:</b></p>
<p>
Solved by
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3069.html">N3069</a>.
</p>


<p id="res-1329"><b>Proposed resolution:</b></p>
<p>
Container data races 23.2.3 <a href="https://wg21.link/container.requirements.dataraces">[container.requirements.dataraces]</a>
</p>

<p>
Paragraph 1 is unchanged as follows:
</p>

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

<p>
Edit paragraph 2 as follows:
</p>

<blockquote><p>
2 Notwithstanding (17.6.4.8), implementations are required to avoid data
races when the contents of the contained object in different elements in
the same sequence<ins>, excepting <code>vector&lt;bool&gt;</code>,</ins>
are modified concurrently.
</p></blockquote>

<p>
Edit paragraph 3 as follows:
</p>

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






</body>
</html>
