<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
 "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>N4070: Improving the specification of the vector execution policy in Parallelism TS</title>
</head>
<body>
<table summary="Identifying information for this document.">
	<tr>
                <th>Doc. No.:</th>
                <td>WG21/N4070</td>
        </tr>
        <tr>
                <th>Date:</th>
                <td>2014-06-20</td>
        </tr>
        <tr>
                <th>Reply to:</th>
                <td>Hans-J. Boehm</td>
        </tr>
        <tr>
                <th>Email:</th>
                <td><a href="mailto:hboehm@google.com">hboehm@google.com</a></td>
        </tr>
</table>
<h1>N4070: Improving the specification of the vector execution policy in Parallelism TS</h1>
<p>
The Parallelism TS currently prohibits synchronization in functions called from vector
algorithms, but says nothing about which standard library functions may invoke
synchronization.  Unfortunately, due to inline expansion, and the possibility of
compiling nested functions in vector mode even if not inlined, this also applies
to nested internal synchronization.
<p>
This is a very rough initial attempt at somewhat pinning this down.  I expect this to
generate PDTS comments.  The reason to apply a rough fix now is to point out the issue,
and hopefully generate much more relevant comments sooner rather than later. 
<h2>Change:</h2>
<p>
Apply the following change to the Parallelism working paper, to 4.1.1p4:
<blockquote>
<p>
The applications of function objects in parallel algorithms invoked with an execution
policy of type <code>parallel_vector_execution_policy</code> are permitted to execute in an unordered
fashion in unspecified threads, and unsequenced <ins>with respect to one another</ins>
within each thread. <del>[ Note: As a
consequence, function objects governed by the parallel_vector_execution_policy policy must
not synchronize with each other. Specifically, they must not acquire locks. -- end note ]</del><ins>[Note: This overrides the usual guarantee from
the C++ standard, Section 1.9 [intro.execution] that function executions do
not interleave with one another.]</ins>
<p>
<ins>Since <code>parallel_vector_execution_policy</code> allows the execution of such function objects
to be interleaved on a single thread, synchronization, including the use of mutexes,
risks deadlock.  Thus the use of synchronization with <code>parallel_vector_execution_policy</code> is restricted as follows:
</ins>
<p>
<ins>A standard library function is <i>vectorization-unsafe</i> if
it is specified to synchronize with another function invocation, or another
function invocation is specified to synchronize
with it, and if it is not a memory allocation or deallocation function.
Vectorization-unsafe standard library functions may not be invoked by
user code called from <code>parallel_vector_execution_policy</code> algorithms.
[Note: Implementations must ensure that internal synchronization
inside standard library routines does not induce deadlock.]</ins>
</blockquote>
</body>
</html>
