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

Use Arc::get_mut instead of Arc::strong_count == 1 #555

Merged
merged 1 commit into from
Mar 3, 2025

Conversation

gmorenz
Copy link
Contributor

@gmorenz gmorenz commented Mar 2, 2025

Arc::strong_count doesn't come with memory ordering guarantees. As such it should be possible to destory the context multiple times with the previous version of this check. I haven't actually seen or attempted to force that to happen, just came across this while reading code.

See rust-lang/rust#117485

Note: The new code is slightly slower (3 atomic operations when only 1 should be necessary, because it checks for weak pointers as well). I can't imagine we care.

Arc::strong_count doesn't come with memory ordering guarantees. As such
it should be possible to destory the context multiple times with the
previous version of this check. 

See rust-lang/rust#117485

Signed-off-by: Greg Morenz <[email protected]>
Copy link
Member

@sagudev sagudev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, everyday I learn something new. Great work!

@sagudev sagudev enabled auto-merge March 3, 2025 05:23
@sagudev sagudev added this pull request to the merge queue Mar 3, 2025
Merged via the queue into servo:main with commit 963d88a Mar 3, 2025
27 checks passed
@gmorenz gmorenz deleted the strong_count branch March 3, 2025 05:58
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