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

OnceLock::get_mut_or_init should not be called concurrently #128429

Closed
juntyr opened this issue Jul 31, 2024 · 1 comment · Fixed by #128457
Closed

OnceLock::get_mut_or_init should not be called concurrently #128429

juntyr opened this issue Jul 31, 2024 · 1 comment · Fixed by #128457
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@juntyr
Copy link
Contributor

juntyr commented Jul 31, 2024

Location

https://doc.rust-lang.org/std/sync/struct.OnceLock.html#method.get_mut_or_init

Summary

The current docs state that

Many threads may call `get_mut_or_init` concurrently with different initializing functions, but it is guaranteed that only one function will be executed.

However, as the method takes a mutable reference, no concurrent calls to this method can occur. If this method was indeed called from several threads, they would need to use external synchronisation to make the access exclusive and not-concurrent. It seems that this text was copy-pasted from the get_or_init sibling method.

@juntyr juntyr added the A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools label Jul 31, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 31, 2024
@jieyouxu jieyouxu added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. C-bug Category: This is a bug. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jul 31, 2024
@tgross35
Copy link
Contributor

That looks like a copy+paste error from get_or_init, easy docs fix for anyone interested.

@tgross35 tgross35 added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jul 31, 2024
@bors bors closed this as completed in 7060a2f Aug 1, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Aug 1, 2024
Rollup merge of rust-lang#128457 - juntyr:once-lock-docs, r=tgross35

Fix docs for OnceLock::get_mut_or_init

Removes an incorrect statment about concurrency from the `OnceLock::get_mut_or_init` (tracked in rust-lang#121641) docs.

Fixes rust-lang#128429
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 C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants