Skip to content

Commit

Permalink
Doc section for sync module on runtime compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jofas committed Sep 9, 2024
1 parent 9116999 commit 05f22e9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
19 changes: 19 additions & 0 deletions tokio/src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,25 @@
//! number of permits, which tasks may request in order to enter a critical
//! section. Semaphores are useful for implementing limiting or bounding of
//! any kind.
//!
//! # Runtime compatibility
//!
//! All synchronization primitives provided in this module are runtime agnostic.
//! You can freely move them between different instances of the Tokio runtime
//! or even use them from non-Tokio runtimes.
//!
//! The only exception to this is the [`mpsc::Sender::send_timeout`] method.
//! It relies on functionality from the [`time`](crate::time) module which
//! does not allow you to call it from non-Tokio runtimes.
//! However, [`Senders`](mpsc::Sender) can still be moved between different
//! instances of the Tokio runtime without you losing the ability to call
//! `send_timeout` on them.
//!
//! When used in a Tokio runtime, the synchronization primitives in this module
//! participate in [cooperative scheduling](crate::task#cooperative-scheduling),
//! periodically yielding back control to the runtime to avoid starving it.
//! This is Tokio specific behavior that does not come into effect when the
//! synchronization primitive is used in a non-Tokio runtime.

cfg_sync! {
/// Named future types.
Expand Down
13 changes: 6 additions & 7 deletions tokio/src/sync/mpsc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,12 @@
//!
//! # Multiple runtimes
//!
//! The mpsc channel does not care about which runtime you use it in, and can be
//! used to send messages from one runtime to another. It can also be used in
//! non-Tokio runtimes.
//!
//! There is one exception to the above: the [`send_timeout`] must be used from
//! within a Tokio runtime, however it is still not tied to one specific Tokio
//! runtime, and the sender may be moved from one Tokio runtime to another.
//! The mpsc channel is runtime agnostic and can be used to send messages
//! between different runtimes, including non-Tokio runtimes.
//! The only exception being [`send_timeout`], which needs to be called from
//! a Tokio runtime.
//! For more details see
//! [the documentation of the `sync` module](crate::sync#runtime-compatibility).
//!
//! # Allocation behavior
//!
Expand Down

0 comments on commit 05f22e9

Please sign in to comment.