Title
task is not actually started lazily
Status
new
Section
[task.promise]
Submitter
Dietmar Kühl

Created on 2025-09-01.00:00:00 last changed 2 weeks ago

Messages

Date: 2025-09-01.20:30:45

Proposed resolution:

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).

Date: 2025-09-01.00:00:00

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.

History
Date User Action Args
2025-09-01 20:30:45adminsetmessages: + msg15010
2025-09-01 00:00:00admincreate