<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2186: Incomplete action on async/launch::deferred</title>
<meta property="og:title" content="Issue 2186: Incomplete action on async/launch::deferred">
<meta property="og:description" content="C++ library issue. Status: C++14">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2186.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#C++14">C++14</a> status.</em></p>
<h3 id="2186"><a href="lwg-defects.html#2186">2186</a>. Incomplete action on <code>async/launch::deferred</code></h3>
<p><b>Section:</b> 32.10.9 <a href="https://wg21.link/futures.async">[futures.async]</a> <b>Status:</b> <a href="lwg-active.html#C++14">C++14</a>
 <b>Submitter:</b> Vicente J. Botet Escriba <b>Opened:</b> 2012-09-20 <b>Last modified:</b> 2017-07-05</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View other</b> <a href="lwg-index-open.html#futures.async">active issues</a> in [futures.async].</p>
<p><b>View all other</b> <a href="lwg-index.html#futures.async">issues</a> in [futures.async].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++14">C++14</a> status.</p>
<p><b>Discussion:</b></p>

<p>
The description of the effects of <code>async</code> when the launch policy is <code>launch::deferred</code> doesn't 
state what is done with the result of the deferred function invocation and the possible exceptions as it is done 
for the asynchronous function when the policy is <code>launch::async</code>.
</p>

<p><i>[2012, Portland: move to Open]</i></p>

<p>
Detlef: agree with the problem but not with the resolution. The wording should be applied to all launch policies
        rather than having to be separately specified for each one.
</p>
<p>
Hans: we should redraft to factor out the proposed text outside the two bullets. Needs to be carefully worded to
      be compatible with the resolution of <a href="lwg-defects.html#2120" title="What should async do if neither 'async' nor 'deferred' is set in policy? (Status: C++14)">2120</a><sup><a href="https://cplusplus.github.io/LWG/issue2120" title="Latest snapshot">(i)</a></sup> (see above).
</p>
<p>
Moved to open
</p>

<p><i>[Issaquah 2014-02-11: Move to Immediate after SG1 review]</i></p>




<p id="res-2186"><b>Proposed resolution:</b></p>
<p><i>[This wording is relative to N3376.]</i></p>


<ol>
<li><p>Change 32.10.9 <a href="https://wg21.link/futures.async">[futures.async]</a> p3 bullet 2 as indicated:</p>
<blockquote><pre>
template &lt;class F, class... Args&gt;
future&lt;typename result_of&lt;typename decay&lt;F&gt;::type(typename decay&lt;Args>::type...)&gt;::type&gt;
async(F&amp;&amp; f, Args&amp;&amp;... args);
template &lt;class F, class... Args&gt;
future&lt;typename result_of&lt;typename decay&lt;F&gt;::type(typename decay&lt;Args&gt;::type...)&gt;::type&gt;
async(launch policy, F&amp;&amp; f, Args&amp;&amp;... args);
</pre><blockquote><p>
-2- <i>Requires</i>: [&hellip;]
<p/>
-3- <i>Effects:</i>: The first function behaves the same as a call to the second function with a <code>policy</code> argument of
<code>launch::async | launch::deferred</code> and the same arguments for <code>F</code> and <code>Args</code>. [&hellip;] The further 
behavior of the second function depends on the <code>policy</code> argument as follows (if more than one of these conditions
applies, the implementation may choose any of the corresponding policies):
</p>
<ul>
<li><p>if <code>policy &amp; launch::async</code> is non-zero [&hellip;]</p></li>
<li><p>if <code>policy &amp; launch::deferred</code> is non-zero &mdash; Stores <code><i>DECAY_COPY</i>(std::forward&lt;F&gt;(f))</code> 
and <code><i>DECAY_COPY</i>(std::forward&lt;Args>(args))...</code> in the shared state. These copies of <code>f</code> and <code>args</code>
constitute a <em>deferred function</em>. Invocation of the deferred function evaluates <code><i>INVOKE</i>(std::move(g), std::move(xyz))</code> 
where <code>g</code> is the stored value of <code><i>DECAY_COPY</i>(std::forward&lt;F>(f))</code> and <code>xyz</code> is
the stored copy of <code><i>DECAY_COPY</i>(std::forward&lt;Args>(args))...</code>. <ins>Any return value is stored as the 
result in the shared state. Any exception propagated from the execution of the deferred function is stored as the 
exceptional result in the shared state.</ins> The shared state is not made ready until the function has completed. 
The first call to a non-timed waiting function (32.10.5 <a href="https://wg21.link/futures.state">[futures.state]</a>) on an asynchronous return object referring 
to this shared state shall invoke the deferred function in the thread that called the waiting function. Once evaluation 
of <code><i>INVOKE</i>(std::move(g), std::move(xyz))</code> begins, the function is no longer considered deferred. 
[<i>Note</i>: If this policy is specified together with other policies, such as when using a policy value of 
<code>launch::async | launch::deferred</code>, implementations should defer invocation or the selection of the <code>policy</code> 
when no more concurrency can be effectively exploited. &mdash; <i>end note</i>]
</p></li>
</ul>
</blockquote></blockquote>
</li>
</ol>






</body>
</html>
