Skip to content

OnceLock::get_mut_or_init should not be called concurrently #128429

Closed
@juntyr

Description

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.

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-bugCategory: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions