Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jwakely opened this issue Oct 3, 2024 · 0 comments
Open

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

jwakely opened this issue Oct 3, 2024 · 0 comments
Labels
SG1 Concurrency

Comments

@jwakely
Copy link
Member

jwakely commented Oct 3, 2024

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.

@jwakely jwakely added the SG1 Concurrency label Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SG1 Concurrency
Projects
None yet
Development

No branches or pull requests

1 participant