28
28
//! undefined behavior to perform two concurrent accesses to the same location from different
29
29
//! threads unless both accesses only read from memory. Notice that this explicitly
30
30
//! includes [`read_volatile`] and [`write_volatile`]: Volatile accesses cannot
31
- //! be used for inter-thread synchronization, regardless of whether it is acting on
31
+ //! be used for inter-thread synchronization, regardless of whether they are acting on
32
32
//! Rust memory or not.
33
33
//! * The result of casting a reference to a pointer is valid for as long as the
34
34
//! underlying allocation is live and no reference (just raw pointers) is used to
@@ -2036,11 +2036,10 @@ pub const unsafe fn write_unaligned<T>(dst: *mut T, src: T) {
2036
2036
/// - When a volatile operation is used for memory inside an [allocation], it behaves exactly like
2037
2037
/// [`read`], except for the additional guarantee that it won't be elided or reordered (see
2038
2038
/// above). This implies that the operation will actually access memory and not e.g. be lowered to
2039
- /// reusing data from a previous read, such as from a register on which previous load of that
2040
- /// memory was performed. Other than that, all the usual rules for memory accesses apply
2041
- /// (including provenance). In particular, just like in C, whether an operation is volatile has
2042
- /// no bearing whatsoever on questions involving concurrent access from multiple threads. Volatile
2043
- /// accesses behave exactly like non-atomic accesses in that regard.
2039
+ /// reusing data from a previous read. Other than that, all the usual rules for memory accesses
2040
+ /// apply (including provenance). In particular, just like in C, whether an operation is volatile
2041
+ /// has no bearing whatsoever on questions involving concurrent accesses from multiple threads.
2042
+ /// Volatile accesses behave exactly like non-atomic accesses in that regard.
2044
2043
///
2045
2044
/// - Volatile operations, however, may also be used to access memory that is _outside_ of any Rust
2046
2045
/// allocation. In this use-case, the pointer does *not* have to be [valid] for reads. This is
@@ -2050,10 +2049,11 @@ pub const unsafe fn write_unaligned<T>(dst: *mut T, src: T) {
2050
2049
/// Here, any address value is possible, including 0 and [`usize::MAX`], so long as the semantics
2051
2050
/// of such a read are well-defined by the target hardware. The provenance of the pointer is
2052
2051
/// irrelevant, and it can be created with [`without_provenance`]. The access must not trap. It
2053
- /// can cause side-effects, but those must not affect Rust-allocated memory in in any way. This
2052
+ /// can cause side-effects, but those must not affect Rust-allocated memory in any way. This
2054
2053
/// access is still not considered [atomic], and as such it cannot be used for inter-thread
2055
- /// synchronization. Note that volatile memory operations where T is a zero-sized type are noops
2056
- /// and may be ignored.
2054
+ /// synchronization.
2055
+ ///
2056
+ /// Note that volatile memory operations where T is a zero-sized type are noops and may be ignored.
2057
2057
///
2058
2058
/// [allocation]: crate::ptr#allocated-object
2059
2059
/// [atomic]: crate::sync::atomic#memory-model-for-atomic-accesses
@@ -2121,7 +2121,7 @@ pub unsafe fn read_volatile<T>(src: *const T) -> T {
2121
2121
/// usage that need to be distinguished:
2122
2122
///
2123
2123
/// - When a volatile operation is used for memory inside an [allocation], it behaves exactly like
2124
- /// [`write() `], except for the additional guarantee that it won't be elided or reordered (see
2124
+ /// [`write`], except for the additional guarantee that it won't be elided or reordered (see
2125
2125
/// above). This implies that the operation will actually access memory and not e.g. be lowered to
2126
2126
/// a register access or stack pop. Other than that, all the usual rules for memory accesses apply
2127
2127
/// (including provenance). In particular, just like in C, whether an operation is volatile has no
@@ -2145,10 +2145,8 @@ pub unsafe fn read_volatile<T>(src: *const T) -> T {
2145
2145
///
2146
2146
/// `write_volatile` does not drop the contents of `dst`. This is safe, but it could leak
2147
2147
/// allocations or resources, so care should be taken not to overwrite an object that should be
2148
- /// dropped when operating on Rust memory.
2149
- ///
2150
- /// Additionally, it does not drop `src`. Semantically, `src` is moved into the location pointed to
2151
- /// by `dst`.
2148
+ /// dropped when operating on Rust memory. Additionally, it does not drop `src`. Semantically, `src`
2149
+ /// is moved into the location pointed to by `dst`.
2152
2150
///
2153
2151
/// [allocation]: crate::ptr#allocated-object
2154
2152
/// [atomic]: crate::sync::atomic#memory-model-for-atomic-accesses
0 commit comments