You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/concurrency.md
+29-2Lines changed: 29 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -107,7 +107,7 @@ fn main() {
107
107
```
108
108
109
109
r[concurrency.atomics.thread-safety]
110
-
Atomic operations are guaranteed to be indivisible: no other thread can observe a value half-written or perform a conflicting update in the middle of an atomic operation. Correct use of atomic types can prevent [data races], but misuse may still cause higher-level concurrency bugs such as deadlocks or livelocks.
110
+
Atomic operations are guaranteed to be indivisible: no other thread can observe a value half-written or perform a conflicting update in the middle of an atomic operation. Correct use of atomic types can prevent [data races], but misuse may still cause higher-level concurrency bugs such as deadlocks or livelocks.
111
111
112
112
```rust
113
113
usestd::sync::atomic::{AtomicUsize, Ordering};
@@ -122,7 +122,7 @@ fn main() {
122
122
t1.join().unwrap();
123
123
t2.join().unwrap();
124
124
125
-
// VALUE is guaranteed to be either 1 or 2 — never a corrupted mix.
125
+
// VALUE is guaranteed to be either 1 or 2, never a corrupted mix.
126
126
println!("{}", VALUE.load(Ordering::Relaxed));
127
127
}
128
128
```
@@ -145,6 +145,33 @@ The following table lists the atomic types and the corresponding primitive types
145
145
|`usize`|[`core::sync::atomic::AtomicUsize`]|
146
146
|`*mut T`|[`core::sync::atomic::AtomicPtr<T>`]|
147
147
148
+
r[concurrency.atomics.usage]
149
+
Atomic types are [`Sync`], meaning references to them can be safely shared between threads. Using atomic operations correctly may require careful reasoning about memory ordering.
0 commit comments