|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4349" status="New"> |
| 5 | +<title><code>task</code> is not actually started lazily</title> |
| 6 | +<section><sref ref="[task.promise]"/></section> |
| 7 | +<submitter>Dietmar Kühl</submitter> |
| 8 | +<date>01 Sep 2025</date> |
| 9 | +<priority>99</priority> |
| 10 | + |
| 11 | +<discussion> |
| 12 | +<p> |
| 13 | +The wording for <code>task<...>::promise_type::initial_suspend</code> |
| 14 | +in <a href="https://wg21.link/task.promise#6">[task.promise] paragraph 6</a> |
| 15 | +(second bullet) may imply that a task is eagerly started, i.e., that the |
| 16 | +awaiter return from <code>initial_suspend()</code> immediately starts |
| 17 | +the scheduling operation and cause the <code>task</code> to be resumed. At |
| 18 | +the very least the second bullet of the wording should be clarified such |
| 19 | +that the scheduling operation is only started when the coroutine gets |
| 20 | +resumed. |
| 21 | +</p> |
| 22 | +<p> |
| 23 | +An alternative resolution it have <code>initial_suspend()</code> |
| 24 | +return <code>std::suspend_always</code> implicitly requiring that |
| 25 | +the <code>task</code> gets <code>start()</code>ed from the correct |
| 26 | +execution context. This approach has the advantage of avoiding |
| 27 | +unnecessary scheduling operations for the likely common case when |
| 28 | +<code>task</code>s are started from the correct context. |
| 29 | +</p> |
| 30 | +</discussion> |
| 31 | + |
| 32 | +<resolution> |
| 33 | +<p> |
| 34 | +Change the declaration of <code>initial_suspend()</code> in the synopsis |
| 35 | +of <a href="https://wg21.link/task.promise#6">[task.promise]</a> to use |
| 36 | +<code>suspend_always</code>, directly provide a definition, and add |
| 37 | +various qualifiers: |
| 38 | +<blockquote> |
| 39 | +<pre> |
| 40 | +namespace std::execution { |
| 41 | + template<class T, class Environment> |
| 42 | + class task<T, Environment>::promise_type { |
| 43 | + ... |
| 44 | + <del>auto</del><ins>static constexpr suspend_always</ins> initial_suspend() noexcept<del>;</del><ins>{ return {}; }</ins> |
| 45 | + ... |
| 46 | + }; |
| 47 | + |
| 48 | +} |
| 49 | +</pre> |
| 50 | +</blockquote> |
| 51 | +</p> |
| 52 | +<p> |
| 53 | +Remove <a href="https://wg21.link/task.promise#6">[task.promise] paragraph 6</a> entirely: |
| 54 | +<blockquote> |
| 55 | +<pre><del>auto initial_suspend() noexcept;</del></pre> |
| 56 | +<p><del>-6- <i>Returns:</i> An awaitable object of unspecified type ([expr.await]) whose member functions arrange for</del></p> |
| 57 | +<p><del>-6.1- - the calling coroutine to be suspended,</del></p> |
| 58 | +<p><del>-6.2- - the coroutine to be resumed on an execution agent of the execution resource associated with <code><i>SCHED</i>(*this)</code>.</del></p> |
| 59 | +</blockquote> |
| 60 | +</p> |
| 61 | +</resolution> |
| 62 | + |
| 63 | +</issue> |
0 commit comments