Fix one more lifetime bug in ensure_started
for cases when the sender is dropped without connecting it
#797
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If the
ensure_started
sender is not connected (i.e. there are no continuations) theensure_started_receiver
holds the last reference to the shared state. This will be released when releasing the operation state until theensure_started
operation state, since theensure_started_receiver
will be released with the operation state. This happens because theensure_started_receiver
is taken by rvalue reference inset_*
. This PR changes them to take the receiver by value, ensuring that the reference count stays non-zero also after the operation state has explicitly been reset.This is another way to fix #795 but I'm keeping that change as it doesn't hurt. Importantly, this fixes a distinct bug that is reported by valgrind in the
std_thread_scheduler
test (the test that callsensure_started
but drops the sender immediately). I've enabled valgrind testing with thestd_thread_scheduler_test
in this PR.