Skip to content

Commit 4ea7da6

Browse files
committed
Doc section for sync module on runtime compatibility
1 parent 9116999 commit 4ea7da6

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

tokio/src/sync/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,20 @@
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) to avoid
443+
//! starvation. This feature does not apply when used from non-Tokio runtimes.
444+
//!
445+
//! As an exception, methods ending in `_timeout` are not runtime agnostic
446+
//! because they require access to the Tokio timer. See the documentation of
447+
//! each `*_timeout` method for more information on its use.
434448
435449
cfg_sync! {
436450
/// Named future types.

tokio/src/sync/mpsc/mod.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,17 @@
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.
73+
//! The `mpsc` channel is runtime agnostic. You can freely move it between
74+
//! different instances of the Tokio runtime or even use it from non-Tokio
75+
//! runtimes.
7676
//!
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.
77+
//! When used in a Tokio runtime, it participates in
78+
//! [cooperative scheduling](crate::task#cooperative-scheduling) to avoid
79+
//! starvation. This feature does not apply when used from non-Tokio runtimes.
80+
//!
81+
//! As an exception, methods ending in `_timeout` are not runtime agnostic
82+
//! because they require access to the Tokio timer. See the documentation of
83+
//! each `*_timeout` method for more information on its use.
8084
//!
8185
//! # Allocation behavior
8286
//!

0 commit comments

Comments
 (0)