Skip to content

Commit 031344e

Browse files
committed
Doc section for sync module on runtime compatibility
1 parent 9116999 commit 031344e

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

tokio/src/sync/mod.rs

+18
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,24 @@
431431
//! number of permits, which tasks may request in order to enter a critical
432432
//! section. Semaphores are useful for implementing limiting or bounding of
433433
//! any kind.
434+
//!
435+
//! # Runtime compatibility
436+
//!
437+
//! All synchronization primitives provided in this module are runtime agnostic.
438+
//! You can freely move them between different instances of the Tokio runtime
439+
//! or even use them from non-Tokio runtimes.
440+
//!
441+
//! When used in a Tokio runtime, the synchronization primitives participate in
442+
//! [cooperative scheduling](crate::task#cooperative-scheduling),
443+
//! periodically yielding back control to the runtime to avoid starving it.
444+
//! In a non-Tokio runtime, the yield points where control is handed back do
445+
//! nothing, not changing the behavior of the synchronization primitive in any
446+
//! way.
447+
//!
448+
//! The only exception to runtime compatibility is the
449+
//! [`mpsc::Sender::send_timeout`] method, which can't be called from non-Tokio
450+
//! runtimes. However, [`Senders`](mpsc::Sender) can still be moved between
451+
//! different instances of the Tokio runtime.
434452
435453
cfg_sync! {
436454
/// Named future types.

tokio/src/sync/mpsc/mod.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,12 @@
7070
//!
7171
//! # Multiple runtimes
7272
//!
73-
//! The mpsc channel does not care about which runtime you use it in, and can be
74-
//! used to send messages from one runtime to another. It can also be used in
75-
//! non-Tokio runtimes.
76-
//!
77-
//! There is one exception to the above: the [`send_timeout`] must be used from
78-
//! within a Tokio runtime, however it is still not tied to one specific Tokio
79-
//! runtime, and the sender may be moved from one Tokio runtime to another.
73+
//! The mpsc channel is runtime agnostic and can be used to send messages
74+
//! between different runtimes, including non-Tokio runtimes.
75+
//! The only exception being [`send_timeout`], which needs to be called from
76+
//! a Tokio runtime.
77+
//! For more details see
78+
//! [the documentation of the `sync` module](crate::sync#runtime-compatibility).
8079
//!
8180
//! # Allocation behavior
8281
//!

0 commit comments

Comments
 (0)