Skip to content

LWG4158 packaged_task::operator= should abandon its shared state #2054

@jwakely

Description

@jwakely

https://cplusplus.github.io/LWG/issue4158

Could SG1 please take a look and confirm that they're happy for us to strike the explicit "Abandons/Releases the shared state" wording from both promise::operator= and packaged_task::operator=.

Technically, the current wording requires abandoning/releasing the state first, before transferring creating the temporary and swapping. After this change, the state will be implicitly abandoned by the temporary's destructor. The difference is observable for packaged_task, because another thread can observe whether the shared state is made ready before or after the stored task is moved to a new packaged_task. However, none of the major std::lib impls actually do it that way, so users aren't getting the order currently specified in the standard anyway.

So this simplifies the spec of promise, and simplifies and fixes the broken spec of packaged_task which previously failed to make the state ready by abandoning it. In both cases the proposed change makes the move-assignment operators safe for self-assignment, so that p = std::move(p) becomes a no-op instead of needlessly abandoning the state and leaving p empty.

Metadata

Metadata

Assignees

No one assigned

    Labels

    LWGLibrary

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions