From f6ecebeae98655de4a3d0dbe3221ddf53360af1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dietmar=20K=C3=BChl?= Date: Mon, 1 Sep 2025 00:32:22 +0100 Subject: [PATCH 1/3] =?UTF-8?q?New=20issue=20from=20Dietmar=20K=C3=BChl:?= =?UTF-8?q?=20task=20is=20not=20actually=20started=20lazily?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xml/issue4349.xml | 63 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 xml/issue4349.xml diff --git a/xml/issue4349.xml b/xml/issue4349.xml new file mode 100644 index 0000000000..bb1424e3d5 --- /dev/null +++ b/xml/issue4349.xml @@ -0,0 +1,63 @@ + + + + +<code>task</code> is not actually started lazily +
+Dietmar Kühl +01 Sep 2025 +99 + + +

+The wording for task<...>::promise_type::initial_suspend +in [task.promise] paragraph 6 +(second bullet) may imply that a task is eagerly started, i.e., that the +awaiter return from initial_suspend() immediately starts +the scheduling operation and cause the task to be resumed. At +the very least the second bullet of the wording should be clarified such +that the scheduling operation is only started when the coroutine gets +resumed. +

+

+An alternative resolution it have initial_suspend() +return std::suspend_always implicitly requiring that +the task gets start()ed from the correct +execution context. This approach has the advantage of avoiding +unnecessary scheduling operations for the likely common case when +tasks are started from the correct context. +

+
+ + +

+Change the declaration of initial_suspend() in the synopsis +of [task.promise] to use +suspend_always, directly provide a definition, and add +various qualifiers: +

+
+namespace std::execution {
+  template<class T, class Environment>
+  class task<T, Environment>::promise_type {
+    ...
+    autostatic constexpr suspend_always initial_suspend() noexcept;{ return {}; }
+    ...
+  };
+
+}
+
+
+

+

+Remove [task.promise] paragraph 6 entirely: +

+
auto initial_suspend() noexcept;
+

-6- Returns: An awaitable object of unspecified type ([expr.await]) whose member functions arrange for

+

-6.1- - the calling coroutine to be suspended,

+

-6.2- - the coroutine to be resumed on an execution agent of the execution resource associated with SCHED(*this).

+
+

+
+ +
From b49df63421413d8da79670a29dcee1f2e7e3bf6d Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Mon, 1 Sep 2025 21:27:04 +0100 Subject: [PATCH 2/3] Apply suggestions from code review --- xml/issue4349.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xml/issue4349.xml b/xml/issue4349.xml index bb1424e3d5..76868e3cd6 100644 --- a/xml/issue4349.xml +++ b/xml/issue4349.xml @@ -11,7 +11,7 @@

The wording for task<...>::promise_type::initial_suspend -in [task.promise] paragraph 6 +in paragraph 6 (second bullet) may imply that a task is eagerly started, i.e., that the awaiter return from initial_suspend() immediately starts the scheduling operation and cause the task to be resumed. At @@ -32,7 +32,7 @@ unnecessary scheduling operations for the likely common case when

Change the declaration of initial_suspend() in the synopsis -of [task.promise] to use +of to use suspend_always, directly provide a definition, and add various qualifiers:

@@ -50,7 +50,7 @@ namespace std::execution {

-Remove [task.promise] paragraph 6 entirely: +Remove paragraph 6 entirely:

auto initial_suspend() noexcept;

-6- Returns: An awaitable object of unspecified type ([expr.await]) whose member functions arrange for

From 6dbe27f313ac49830d6668a5bb580ac95a18ff9c Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Mon, 1 Sep 2025 21:29:15 +0100 Subject: [PATCH 3/3] Update xml/issue4349.xml --- xml/issue4349.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xml/issue4349.xml b/xml/issue4349.xml index 76868e3cd6..1aada82a3c 100644 --- a/xml/issue4349.xml +++ b/xml/issue4349.xml @@ -11,7 +11,7 @@

The wording for task<...>::promise_type::initial_suspend -in paragraph 6 +in paragraph 6 (second bullet) may imply that a task is eagerly started, i.e., that the awaiter return from initial_suspend() immediately starts the scheduling operation and cause the task to be resumed. At