This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.

4349. task is not actually started lazily

Section: 33.13.6.5 [task.promise] Status: New Submitter: Dietmar Kühl Opened: 2025-09-01 Last modified: 2025-09-01

Priority: Not Prioritized

View other active issues in [task.promise].

View all other issues in [task.promise].

View all issues with New status.

Discussion:

The wording for task<...>::promise_type::initial_suspend in 33.13.6.5 [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.

Proposed resolution:

Change the declaration of initial_suspend() in the synopsis of 33.13.6.5 [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 33.13.6.5 [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).