Skip to content

Commit f38b04b

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

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

tokio/src/sync/mod.rs

+19
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,25 @@
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+
//! The only exception to this is the [`mpsc::Sender::send_timeout`] method.
442+
//! It relies on functionality from the [`time`](crate::time) module which
443+
//! does not allow you to call it from non-Tokio runtimes.
444+
//! However, [`Senders`](mpsc::Sender) can still be moved between different
445+
//! instances of the Tokio runtime without you losing the ability to call
446+
//! `send_timeout` on them.
447+
//!
448+
//! When used in a Tokio runtime, the synchronization primitives in this module
449+
//! participate in [cooperative scheduling](crate::task#cooperative-scheduling),
450+
//! periodically yielding back control to the runtime to avoid starving it.
451+
//! This is Tokio specific behaviour that does not come into effect when the
452+
//! synchronization primitive is used in a non-Tokio runtime.
434453
435454
cfg_sync! {
436455
/// 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)