Skip to content

Commit 43b2a60

Browse files
Rollup merge of rust-lang#157694 - xmh0511:main, r=Darksonn
Enhance documentation on wake call memory ordering
2 parents b12c362 + 42538ca commit 43b2a60

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

library/alloc/src/task.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ use crate::sync::Arc;
3737
/// link ../../std/task/struct.Waker.html#impl-From%3CArc%3CW,+Global%3E%3E-for-Waker
3838
/// without getting a link-checking error in CI. -->
3939
///
40+
/// # Memory Ordering
41+
///
42+
/// To avoid missed wakeups, all executors must adhere to the requirement described for [`Waker::wake`].
43+
///
4044
/// # Examples
4145
///
4246
/// A basic `block_on` function that takes a future and runs it to completion on

library/core/src/task/wake.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -418,15 +418,16 @@ unsafe impl Sync for Waker {}
418418
impl Waker {
419419
/// Wakes up the task associated with this `Waker`.
420420
///
421-
/// As long as the executor keeps running and the task is not finished, it is
422-
/// guaranteed that each invocation of [`wake()`](Self::wake) (or
421+
/// As long as the executor keeps running and the task is not finished,
422+
/// it is guaranteed that each invocation of [`wake()`](Self::wake) (or
423423
/// [`wake_by_ref()`](Self::wake_by_ref)) will be followed by at least one
424-
/// [`poll()`] of the task to which this `Waker` belongs. This makes
425-
/// it possible to temporarily yield to other tasks while running potentially
426-
/// unbounded processing loops.
424+
/// [`poll()`] of the task to which this `Waker` belongs, such that the call to
425+
/// [`wake()`](Self::wake) (or [`wake_by_ref()`](Self::wake_by_ref)) _happens-before_
426+
/// the beginning of the invocation of [`poll()`]. This makes it possible to temporarily
427+
/// yield to other tasks while running potentially unbounded processing loops.
427428
///
428429
/// Note that the above implies that multiple wake-ups may be coalesced into a
429-
/// single [`poll()`] invocation by the runtime.
430+
/// single [`poll()`] invocation by the executor.
430431
///
431432
/// Also note that yielding to competing tasks is not guaranteed: it is the
432433
/// executor’s choice which task to run and the executor may choose to run the

0 commit comments

Comments
 (0)