<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2533: [concurr.ts] Constrain threads where future::then can run a continuation</title>
<meta property="og:title" content="Issue 2533: [concurr.ts] Constrain threads where future::then can run a continuation">
<meta property="og:description" content="C++ library issue. Status: SG1">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2533.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#SG1">SG1</a> status.</em></p>
<h3 id="2533"><a href="lwg-active.html#2533">2533</a>. [concurr.ts] Constrain threads where <code>future::then</code> can run a continuation</h3>
<p><b>Section:</b> 99 [concurr.ts::futures.unique.future] <b>Status:</b> <a href="lwg-active.html#SG1">SG1</a>
 <b>Submitter:</b> Agust&iacute;n K-ballo Berg&eacute; <b>Opened:</b> 2015-09-03 <b>Last modified:</b> 2021-06-06</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#SG1">SG1</a> status.</p>
<p><b>Discussion:</b></p>
<p><b>Addresses: concurr.ts</b></p>
<p>
In <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4538.pdf">N4538</a>, the continuation given to
<code>future::then</code> can be run "on an unspecified thread of execution". This is too broad, as it allows the
continuation to be run on the main thread, a UI thread, or any other thread. In comparison, functions given to
<code>async</code> run "as if in a new thread of execution", while the Parallelism TS gives less guarantees by running
"in either the invoking thread or in a thread implicitly created by the library to support parallel algorithm execution".
The threads on which the continuation given to <code>future::then</code> can run should be similarly constrained.
</p>

<p><i>[2017-03-01, Kona, SG1]</i></p>

<p>
Agreement that this is a problem. Suggested addition to the issue is below. We have no immediate delivery vehicle
for a fix at the moment, but we would like to make the intended direction clear.
<p/>
There is SG1 consensus that <code>.then</code> continuations should, by default, and in the absence of executors, be run
only in the following ways:
</p>
<ol>
<li><p>If the future is not ready when <code>.then()</code> is called, the <code>.then</code> argument may be run on the execution
agent that fulfills the promise.</p></li>
<li><p>In all cases, the <code>.then</code> argument may be run on an implementation-provided thread, i.e. a thread that is
neither the main thread nor explicitly created by the user.</p></li>
</ol>
<p>
In the absence of an executor argument (which currently cannot be supplied), running of the <code>.then()</code> continuation
will not block the thread calling <code>.then()</code>, even if the future is ready at the time.
<p/>
Straw polls:
<p/>
SF | F | N | A | SA
<p/>
For the default behaviour:
<p/>
"1. Run on completed task or new execution agent"
<p/>
0 | 7 | 5 | 1 | 0
<p/>
"2. Run on completed task or <code>.then</code> caller"
<p/>
0 | 0 | 5 | 5 | 3
<p/>
"3. Leave as implementation defined"
<p/>
1 | 2 | 4 | 3 | 3
<p/>
"4. Always new execution agent"
<p/>
2 | 3 | 6 | 2 | 0
<p/>
The actual conclusion was to allow either (1) or (4) for now, since they are quite close, but present a very different
programming mode from (2).
</p>


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





</body>
</html>
