Skip to content

Commit

Permalink
sync: document mpsc channel allocation behavior
Browse files Browse the repository at this point in the history
Fixes: #6754
  • Loading branch information
barafael committed Aug 13, 2024
1 parent 694577f commit 5241e22
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tokio/src/sync/mpsc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@
//! 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.
//!
//! # Allocation behavior
//!
//! <div class="warning">The behavior documented here may change</div>
//!
//! The mpsc channel stores elements in chunks. Chunks are organized in a linked list. Sending
//! pushes new elements onto the front of the list, and receiving pops them off the back. A chunk
//! can hold 32 messages (regardless of channel and message size). Each chunk also stores 4
//! pointer-sized values for bookkeeping (so on a 64-bit machine, each message has 1 byte of
//! overhead).
//!
//! When all values in a chunk have been received, it becomes empty. It will then be freed, unless
//! the channels first chunk (where newly-sent elements are being stored) has no next chunk. In
//! that case, the empty chunk is reused as the next chunk.
//!
//! [`Sender`]: crate::sync::mpsc::Sender
//! [`Receiver`]: crate::sync::mpsc::Receiver
//! [bounded-send]: crate::sync::mpsc::Sender::send()
Expand Down

0 comments on commit 5241e22

Please sign in to comment.