Skip to content

Commit 884971f

Browse files
committed
Improve and expand documentation of pipes
- Reference UNIX, not just Linux - Simplify some of the language - Don't imply that pipes *only* work across multiple processes; instead, *suggest* that they're typically used across two or more separate processes. - Specify that portable applications cannot use multiple readers or multiple writers for messages larger than a byte, due to potential interleaving.
1 parent f2b91cc commit 884971f

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

library/std/src/pipe.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
//! A cross-platform anonymous pipe.
22
//!
3-
//! This module provides support for anonymous OS pipes, like [pipe] on Linux or [CreatePipe] on
4-
//! Windows.
3+
//! This module provides support for anonymous OS pipes, like [pipe] on UNIX/Linux or [CreatePipe]
4+
//! on Windows.
55
//!
66
//! # Behavior
77
//!
8-
//! A pipe is a synchronous, unidirectional data channel between two or more processes, like an
9-
//! interprocess [`mpsc`](crate::sync::mpsc) provided by the OS. In particular:
8+
//! A pipe is a one-way data channel provided by the OS, which works across processes. A pipe is
9+
//! typically used to communicate between two or more separate processes, as there are better,
10+
//! faster ways to communicate within a single process.
11+
//!
12+
//! In particular:
1013
//!
1114
//! * A read on a [`PipeReader`] blocks until the pipe is non-empty.
1215
//! * A write on a [`PipeWriter`] blocks when the pipe is full.
1316
//! * When all copies of a [`PipeWriter`] are closed, a read on the corresponding [`PipeReader`]
1417
//! returns EOF.
15-
//! * [`PipeReader`] can be shared, but only one process will consume the data in the pipe.
18+
//! * [`PipeWriter`] can be shared, and multiple processes or threads can write to it at once, but
19+
//! writes (above a target-specific threshold) may have their data interleaved.
20+
//! * [`PipeReader`] can be shared, and multiple processes or threads can read it at once. Any
21+
//! given byte will only get consumed by one reader. There are no guarantees about data
22+
//! interleaving.
23+
//! * Portable applications cannot assume any atomicity of messages larger than a single byte.
1624
//!
1725
//! # Capacity
1826
//!

0 commit comments

Comments
 (0)