Skip to content

[6.0][Concurrency] Retain the actor around the CAS in enqueue() when necessary. #77079

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

Merged
merged 1 commit into from
Oct 18, 2024

Conversation

mikeash
Copy link
Contributor

@mikeash mikeash commented Oct 17, 2024

Cherry-pick #77031 to release/6.0.

It's possible that the job we enqueue holds the last strong reference to the actor. If that job runs on another thread after we enqueue it, then it's possible for this to be destroyed while we're still in this function. We need to use this after the enqueue when the priorities don't match. When it looks like that will happen, retain this before the enqueue to ensure it stays alive until we're done with it.

Introduce a defensive retain helper class that makes it easy to do a single retain under certain conditions even in a loop, and does RAII to balance it with a release when the scope exits.

rdar://135400933

…necessary.

It's possible that the job we enqueue holds the last strong reference to the actor. If that job runs on another thread after we enqueue it, then it's possible for `this` to be destroyed while we're still in this function. We need to use `this` after the enqueue when the priorities don't match. When it looks like that will happen, retain `this` before the enqueue to ensure it stays alive until we're done with it.

Introduce a defensive retain helper class that makes it easy to do a single retain under certain conditions even in a loop, and does RAII to balance it with a release when the scope exits.

rdar://135400933
(cherry picked from commit 6b01fed)
@mikeash mikeash requested a review from a team as a code owner October 17, 2024 17:41
@mikeash
Copy link
Contributor Author

mikeash commented Oct 17, 2024

@swift-ci please test

@mikeash mikeash enabled auto-merge October 17, 2024 17:53
@mikeash mikeash merged commit db4aa81 into swiftlang:release/6.0 Oct 18, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants