Skip to content

Commit 9ab403c

Browse files
committed
Clarify overlapping accesses in Atomic*::from_ptr docs
1 parent e0467f8 commit 9ab403c

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

library/core/src/sync/atomic.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,11 @@ impl AtomicBool {
357357
/// duration of lifetime `'a`. Most use cases should be able to follow this guideline.
358358
/// * This requirement is also trivially satisfied if all accesses (atomic or not) are done
359359
/// from the same thread.
360-
/// * This method must not be used to perform overlapping or mixed-size atomic
361-
/// accesses, as these are not supported by the memory model.
360+
/// * Atomic accesses that overlap must either all use the same address and size,
361+
/// or they must have a happens-before relationship.
362+
/// * In other words, within one of the atomic time periods mentioned in the previous
363+
/// bullet, there cannot be accesses to the same value that overlap only partially.
364+
/// They must either not overlap at all or overlap perfectly.
362365
///
363366
/// [valid]: crate::ptr#safety
364367
#[stable(feature = "atomic_from_ptr", since = "CURRENT_RUSTC_VERSION")]
@@ -1161,8 +1164,11 @@ impl<T> AtomicPtr<T> {
11611164
/// duration of lifetime `'a`. Most use cases should be able to follow this guideline.
11621165
/// * This requirement is also trivially satisfied if all accesses (atomic or not) are done
11631166
/// from the same thread.
1164-
/// * This method must not be used to perform overlapping or mixed-size atomic accesses, as
1165-
/// these are not supported by the memory model.
1167+
/// * Atomic accesses that overlap must either all use the same address and size,
1168+
/// or they must have a happens-before relationship.
1169+
/// * In other words, within one of the atomic time periods mentioned in the previous
1170+
/// bullet, there cannot be accesses to the same value that overlap only partially.
1171+
/// They must either not overlap at all or overlap perfectly.
11661172
///
11671173
/// [valid]: crate::ptr#safety
11681174
#[stable(feature = "atomic_from_ptr", since = "CURRENT_RUSTC_VERSION")]
@@ -2144,8 +2150,11 @@ macro_rules! atomic_int {
21442150
/// this guideline.
21452151
/// * This requirement is also trivially satisfied if all accesses (atomic or not) are
21462152
/// done from the same thread.
2147-
/// * This method must not be used to perform overlapping or mixed-size atomic
2148-
/// accesses, as these are not supported by the memory model.
2153+
/// * Atomic accesses that overlap must either all use the same address and size,
2154+
/// or they must have a happens-before relationship.
2155+
/// * In other words, within one of the atomic time periods mentioned in the previous
2156+
/// bullet, there cannot be accesses to the same value that overlap only partially.
2157+
/// They must either not overlap at all or overlap perfectly.
21492158
///
21502159
/// [valid]: crate::ptr#safety
21512160
#[stable(feature = "atomic_from_ptr", since = "CURRENT_RUSTC_VERSION")]

0 commit comments

Comments
 (0)