<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2538: [parallel.ts] Requirements on data race behavior of iterators and swap should be clarified</title>
<meta property="og:title" content="Issue 2538: [parallel.ts] Requirements on data race behavior of iterators and swap should be clarified">
<meta property="og:description" content="C++ library issue. Status: NAD">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2538.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#NAD">NAD</a> status.</em></p>
<h3 id="2538"><a href="lwg-closed.html#2538">2538</a>. [parallel.ts] Requirements on data race behavior of iterators and swap should be clarified</h3>
<p><b>Section:</b> 99 [parallel.ts::parallel.alg.general.exec] <b>Status:</b> <a href="lwg-active.html#NAD">NAD</a>
 <b>Submitter:</b> Robert Geva <b>Opened:</b> 2015-09-22 <b>Last modified:</b> 2015-10-21</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#NAD">NAD</a> status.</p>
<p><b>Discussion:</b></p>
<p><b>Addresses: parallel.ts</b></p>
<p>
Parallel algorithms as of <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4352.html">N4352</a> in general 
need to assume that iterator operations and <code>swap</code> have the expected data race behavior.  
For example, <code>sort</code> would not work if the exchange operation were thread-unsafe and, for example, always updated a single 
unprotected global counter, independent of the objects being swapped. A parallel <code>sort</code> has to be able to assume that disjoint 
pairs of objects can be swapped concurrently, i.e. that elemental functions have the same sort of thread-safety behavior that 
we generally promise for the standard library versions. I don't see that assumption stated anywhere.
<p/>
We should then probably also be clearer that the 99 [parallel.ts::parallel.alg.general.exec] ordering rules are further 
constrained by algorithm correctness requirements, and by the requirement not to introduce data races when elemental functions 
satisfy their thread-safety expectations. 
<p/>
It's tempting to generally add basic thread-safety requirements to various library requirements clauses. But that adds backwards 
compatibility issues for single-threaded code.
<p/>
Most probably this applies to other operations as well. We do state in [parallel.alg.general.user]:
</p>
<blockquote class="note"><p>
Function objects passed into parallel algorithms as objects of type <code>BinaryPredicate</code>, <code>Compare</code>, and 
<code>BinaryOperation</code> shall not directly or indirectly modify objects via their arguments.
</p></blockquote>
<p>
But that only seems to cover the easy cases.
</p>


<p id="res-2538"><b>Proposed resolution:</b></p>





</body>
</html>
