Skip to content

Commit 0bd9f90

Browse files
committed
Add multi-producer, multi-consumer channel (mpmc)
1 parent 25c9f2c commit 0bd9f90

File tree

8 files changed

+1759
-52
lines changed

8 files changed

+1759
-52
lines changed

library/std/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
//! the [`io`], [`fs`], and [`net`] modules.
150150
//!
151151
//! The [`thread`] module contains Rust's threading abstractions. [`sync`]
152-
//! contains further primitive shared memory types, including [`atomic`] and
152+
//! contains further primitive shared memory types, including [`atomic`], [`mpmc`] and
153153
//! [`mpsc`], which contains the channel types for message passing.
154154
//!
155155
//! # Use before and after `main()`
@@ -173,6 +173,7 @@
173173
//! - after-main use of thread-locals, which also affects additional features:
174174
//! - [`thread::current()`]
175175
//! - [`thread::scope()`]
176+
//! - [`sync::mpmc`]
176177
//! - [`sync::mpsc`]
177178
//! - before-main stdio file descriptors are not guaranteed to be open on unix platforms
178179
//!
@@ -198,6 +199,7 @@
198199
//! [`atomic`]: sync::atomic
199200
//! [`for`]: ../book/ch03-05-control-flow.html#looping-through-a-collection-with-for
200201
//! [`str`]: prim@str
202+
//! [`mpmc`]: sync::mpmc
201203
//! [`mpsc`]: sync::mpsc
202204
//! [`std::cmp`]: cmp
203205
//! [`std::slice`]: mod@slice

library/std/src/sync/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@
130130
//! inter-thread synchronisation mechanism, at the cost of some
131131
//! extra memory.
132132
//!
133+
//! - [`mpmc`]: Multi-producer, multi-consumer queues, used for
134+
//! message-based communication. Can provide a lightweight
135+
//! inter-thread synchronisation mechanism, at the cost of some
136+
//! extra memory.
137+
//!
133138
//! - [`Mutex`]: Mutual Exclusion mechanism, which ensures that at
134139
//! most one thread at a time is able to access some data.
135140
//!
@@ -150,6 +155,7 @@
150155
//! [`Arc`]: crate::sync::Arc
151156
//! [`Barrier`]: crate::sync::Barrier
152157
//! [`Condvar`]: crate::sync::Condvar
158+
//! [`mpmc`]: crate::sync::mpmc
153159
//! [`mpsc`]: crate::sync::mpsc
154160
//! [`Mutex`]: crate::sync::Mutex
155161
//! [`Once`]: crate::sync::Once
@@ -191,12 +197,13 @@ pub use self::once_lock::OnceLock;
191197
#[unstable(feature = "reentrant_lock", issue = "121440")]
192198
pub use self::reentrant_lock::{ReentrantLock, ReentrantLockGuard};
193199

200+
#[unstable(feature = "mpmc_channel", issue = "125712")]
201+
pub mod mpmc;
194202
pub mod mpsc;
195203

196204
mod barrier;
197205
mod condvar;
198206
mod lazy_lock;
199-
mod mpmc;
200207
mod mutex;
201208
pub(crate) mod once;
202209
mod once_lock;

library/std/src/sync/mpmc/error.rs

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub use crate::sync::mpsc::{RecvError, RecvTimeoutError, SendError, TryRecvError
99
///
1010
/// [`send_timeout`]: super::Sender::send_timeout
1111
#[derive(PartialEq, Eq, Clone, Copy)]
12+
#[unstable(feature = "mpmc_channel", issue = "125712")]
1213
pub enum SendTimeoutError<T> {
1314
/// The message could not be sent because the channel is full and the operation timed out.
1415
///
@@ -20,12 +21,14 @@ pub enum SendTimeoutError<T> {
2021
Disconnected(T),
2122
}
2223

24+
#[unstable(feature = "mpmc_channel", issue = "125712")]
2325
impl<T> fmt::Debug for SendTimeoutError<T> {
2426
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2527
"SendTimeoutError(..)".fmt(f)
2628
}
2729
}
2830

31+
#[unstable(feature = "mpmc_channel", issue = "125712")]
2932
impl<T> fmt::Display for SendTimeoutError<T> {
3033
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3134
match *self {
@@ -35,8 +38,10 @@ impl<T> fmt::Display for SendTimeoutError<T> {
3538
}
3639
}
3740

41+
#[unstable(feature = "mpmc_channel", issue = "125712")]
3842
impl<T> error::Error for SendTimeoutError<T> {}
3943

44+
#[unstable(feature = "mpmc_channel", issue = "125712")]
4045
impl<T> From<SendError<T>> for SendTimeoutError<T> {
4146
fn from(err: SendError<T>) -> SendTimeoutError<T> {
4247
match err {

0 commit comments

Comments
 (0)