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

mention Arc::make_mut alongside Mutex #138322

Closed
lolbinarycat opened this issue Mar 10, 2025 · 1 comment · Fixed by #138341
Closed

mention Arc::make_mut alongside Mutex #138322

lolbinarycat opened this issue Mar 10, 2025 · 1 comment · Fixed by #138341
Assignees
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools needs-triage This issue may need triage. Remove it if it has been sufficiently triaged.

Comments

@lolbinarycat
Copy link
Contributor

lolbinarycat commented Mar 10, 2025

Location

https://doc.rust-lang.org/stable/std/sync/struct.Arc.html

Summary

The prose here mentions how Arc does not provide interior mutability, but in many cases you don't actually need shared interior mutability, just the ability to effeciently mutate something that happens to be in an Arc.

Seeing how many people who are new to rust gravitate towards Arc<Mutex<T>> to avoid dealing with references, it would probably be good to mention copy-on-write semantics as an alternative.

@lolbinarycat lolbinarycat added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Mar 10, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 10, 2025
@xizheyin
Copy link
Contributor

Shared interior mutability, i.e. Arc<Mutex<T>> can cause performance degradation, I can try this. I made this mistake once.

@rustbot claim

@bors bors closed this as completed in 625278b Mar 17, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 17, 2025
Rollup merge of rust-lang#138341 - xizheyin:issue-138322, r=joboet

std: Mention clone-on-write mutation in Arc<T>

Fixes rust-lang#138322

r? libs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools needs-triage This issue may need triage. Remove it if it has been sufficiently triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants