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.

4347. task's stop source is always created

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 type task<...>::promise_type has exposition-only members source and token. These can be interpreted as always existing which would be a performance issue for former and an unnecessary constraints for the latter (because stop tokens aren't required to be default constructible).

The intent is that the stop token obtained from the get_stop_token query of the receiver's environment is used. Only if this type is different from the task's stop_token_type a stop source of type stop_source_type needs to be created when the get_stop_token query is used on the promise type's environment. The stop token doesn't need to be stored at all: it can either be obtained from the receiver's environment or from the stop source. The fix is to show the stop source as an optionally present member of of the operation state and it should be of type std::optional<stop_source_type> to imply that it is only created when accessed.

Proposed resolution: