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
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,8 +14,9 @@ The [`Send`] and [`Sync`] traits are `unsafe` [auto traits] used by the Rust typ
14
14
15
15
These traits are [marker traits] with no methods. Implementing them asserts that a type has the intrinsic properties required for safe concurrent use. The compiler automatically implements these traits for most types when possible, but they can also be implemented manually. Because other unsafe code may rely on these traits being correctly implemented, providing an incorrect manual implementation can cause [undefined behavior].
16
16
17
-
r[concurrency.send-and-sync.]
18
-
Some types, such as [`Rc`], [`UnsafeCell`], [`Cell`], and [`RefCell`], intentionally do not implement [`Send`] or [`Sync`]. These types enable unsynchronized shared mutable state, which would be `unsafe` to transfer or share across threads.
17
+
r[concurrency.send-and-sync.non-implementors]
18
+
Some types, such as [`Rc`], [`UnsafeCell`], [`Cell`], and [`RefCell`], intentionally do not implement [`Send`] or [`Sync`]. These types enable unsynchronized shared mutable state, which would be unsafe to transfer or share across threads.
19
+
19
20
r[concurrency.send-and-sync.send]
20
21
### Send
21
22
@@ -24,7 +25,7 @@ The [`Send`] trait indicates that ownership of values of a type can be safely tr
24
25
25
26
r[concurrency.send-and-sync.send.rules]
26
27
1. A type that implements [`Send`] can be moved to another thread and used there without causing data races or other [undefined behavior].
27
-
2. The Rust compiler automatically implements [`Send`] for types that satisfy its requirements (see the [`Send` documentation] for details on which types automatically implement this trait).
28
+
2. The Rust compiler automatically implements [`Send`] for types that satisfy its requirements (see the [`Send` documentation] for examples of types that automatically implement this trait).
28
29
3. Manually implementing [`Send`] is `unsafe`. Such implementations must ensure that moving a value of that type to another thread cannot violate Rust’s aliasing or mutability guarantees.
@@ -49,7 +50,7 @@ The [`Sync`] trait indicates that references (`&T`) to a type can be safely shar
49
50
50
51
r[concurrency.send-and-sync.sync.rules]
51
52
1. If a type (`T`) is [`Sync`], then (`&T`) is [`Send`]: immutable references to type (`T`) can be sent to other threads and accessed there concurrently.
52
-
2. The Rust compiler automatically implements [`Sync`] for types that satisfy its requirements (see the [`Sync` documentation] for details on which types automatically implement this trait).
53
+
2. The Rust compiler automatically implements [`Sync`] for types that satisfy its requirements (see the [`Sync` documentation] for examples of types that automatically implement this trait).
53
54
3. Manually implementing [`Sync`] is `unsafe`. Such implementations must ensure that concurrent shared access to values of that type cannot lead to data races or other [undefined behavior].
@@ -94,7 +95,7 @@ The following table lists the atomic types and the corresponding primitive types
94
95
|`*mut T`|[`core::sync::atomic::AtomicPtr<T>`]|
95
96
96
97
r[concurrency.atomics.usage]
97
-
Atomic types are [`Sync`], meaning references to them can be safely shared between threads. However, atomic operations operate at the hardware level and require careful reasoning about memory ordering. Most programs should prefer higher-level concurrency primitives such as [`Mutex`] or [`RwLock`] unless fine-grained lock-free programming is required. While atomic operations prevent [data races] at the hardware level, they do not inherently enforce higher-level invariants. Complex coordination may still require locks or other synchronization primitives.
98
+
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.
98
99
99
100
r[concurrency.asynchronous-computation]
100
101
## Asynchronous Computation
@@ -110,9 +111,8 @@ The result of a future is obtained in one of two ways:
110
111
1. Using an [`await` expression] (`future.await`), which implicitly polls the future until it is ready.
111
112
2. By explicitly invoking [`core::future::Future::poll`].
112
113
113
-
r[concurrency.async.rules]
114
-
1. Once a future has returned [`core::task::Poll::Ready`], it must not be polled again.
115
-
2. Polling a future that has already completed is [undefined behavior].
114
+
r[concurrency.async.rule]
115
+
Once a future has returned [`core::task::Poll::Ready`], it must not be polled again. Doing so may panic, block forever, or cause other kinds of problems.
0 commit comments