File tree 1 file changed +20
-0
lines changed
1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 79
79
//!
80
80
//! [lock-free]: https://en.wikipedia.org/wiki/Non-blocking_algorithm
81
81
//!
82
+ //! # Atomic accesses to read-only memory
83
+ //!
84
+ //! In general, atomic accesses on read-only memory are Undefined Behavior. For instance, attempting
85
+ //! to do a `compare_exchange` that will definitely fail (making it conceptually a read-only
86
+ //! operation) can still cause a page fault if the underlying memory page is mapped read-only. Since
87
+ //! atomic `load`s might be implemented using compare-exchange operations, even a `load` can fault
88
+ //! on read-only memory.
89
+ //!
90
+ //! However, as an exception from this general rule, Rust guarantees that "sufficiently small"
91
+ //! atomic loads are implemented in a way that works on read-only memory. This threshold of
92
+ //! "sufficiently small" depends on the architecture:
93
+ //!
94
+ //! | Target architecture | Maximal atomic `load` size that is guaranteed read-only |
95
+ //! |----------|---------|
96
+ //! | `x86` | 4 bytes |
97
+ //! | `x86_64` | 8 bytes |
98
+ //!
99
+ //! Any atomic `load` on read-only memory larger than the given size are Undefined Behavior. For
100
+ //! architectures not listed above, all atomic `load` on read-only memory are Undefined Behavior.
101
+ //!
82
102
//! # Examples
83
103
//!
84
104
//! A simple spinlock:
You can’t perform that action at this time.
0 commit comments