-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Atomic*::as_ptr unnecessarily restricts operations on the pointer to atomic operations #138246
Copy link
Copy link
Closed
Closed
Copy link
Labels
A-atomicArea: Atomics, barriers, and sync primitivesArea: Atomics, barriers, and sync primitivesA-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsE-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.T-opsemRelevant to the opsem teamRelevant to the opsem team
Metadata
Metadata
Assignees
Labels
A-atomicArea: Atomics, barriers, and sync primitivesArea: Atomics, barriers, and sync primitivesA-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsE-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.T-opsemRelevant to the opsem teamRelevant to the opsem team
Type
Fields
Give feedbackNo fields configured for issues without a type.
Location
https://doc.rust-lang.org/std/sync/atomic/struct.AtomicUsize.html#method.as_ptr
Summary
PR #136669 and PR #138000 make it clear that we should be able to safely do a non-atomic read of an atomic in certain circumstances. The most natural way to do the non-atomic read is to use
as_ptr()and then do a read through the pointer.However, the documentation for
as_ptr()disallow any non-atomic operation on the pointer it returns, at odds with the aforementioned PRs. I believe the statement "operations on it must be atomic" should be replaced with a reference to the documentation in https://doc.rust-lang.org/std/sync/atomic/index.html#memory-model-for-atomic-accesses.(NIT: I don't think "Any use of the returned raw pointer requires an unsafe block" is correct or particularly useful. That seems to be justifying the addition of the function, not helping people use it. Presumably pointer comparison or other operations can be done that don't require an
unsafeblock.)/cc @RalfJung