Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8dd5cd0

Browse files
committed
Auto merge of #126839 - obeis:mpmc, r=Amanieu
Add multi-producer, multi-consumer channel (mpmc) Closes #125712 Tracking issue: #126840 r? m-ou-se
2 parents c4f7176 + 041e76b commit 8dd5cd0

File tree

8 files changed

+1758
-52
lines changed

8 files changed

+1758
-52
lines changed

‎library/std/src/lib.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
//! the [`io`], [`fs`], and [`net`] modules.
154154
//!
155155
//! The [`thread`] module contains Rust's threading abstractions. [`sync`]
156-
//! contains further primitive shared memory types, including [`atomic`] and
156+
//! contains further primitive shared memory types, including [`atomic`], [`mpmc`] and
157157
//! [`mpsc`], which contains the channel types for message passing.
158158
//!
159159
//! # Use before and after `main()`
@@ -177,6 +177,7 @@
177177
//! - after-main use of thread-locals, which also affects additional features:
178178
//! - [`thread::current()`]
179179
//! - [`thread::scope()`]
180+
//! - [`sync::mpmc`]
180181
//! - [`sync::mpsc`]
181182
//! - before-main stdio file descriptors are not guaranteed to be open on unix platforms
182183
//!
@@ -202,6 +203,7 @@
202203
//! [`atomic`]: sync::atomic
203204
//! [`for`]: ../book/ch03-05-control-flow.html#looping-through-a-collection-with-for
204205
//! [`str`]: prim@str
206+
//! [`mpmc`]: sync::mpmc
205207
//! [`mpsc`]: sync::mpsc
206208
//! [`std::cmp`]: cmp
207209
//! [`std::slice`]: mod@slice

‎library/std/src/sync/mod.rs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@
133133
//! inter-thread synchronisation mechanism, at the cost of some
134134
//! extra memory.
135135
//!
136+
//! - [`mpmc`]: Multi-producer, multi-consumer queues, used for
137+
//! message-based communication. Can provide a lightweight
138+
//! inter-thread synchronisation mechanism, at the cost of some
139+
//! extra memory.
140+
//!
136141
//! - [`Mutex`]: Mutual Exclusion mechanism, which ensures that at
137142
//! most one thread at a time is able to access some data.
138143
//!
@@ -153,6 +158,7 @@
153158
//! [`Arc`]: crate::sync::Arc
154159
//! [`Barrier`]: crate::sync::Barrier
155160
//! [`Condvar`]: crate::sync::Condvar
161+
//! [`mpmc`]: crate::sync::mpmc
156162
//! [`mpsc`]: crate::sync::mpsc
157163
//! [`Mutex`]: crate::sync::Mutex
158164
//! [`Once`]: crate::sync::Once
@@ -193,12 +199,13 @@ pub use self::rwlock::{MappedRwLockReadGuard, MappedRwLockWriteGuard};
193199
#[stable(feature = "rust1", since = "1.0.0")]
194200
pub use self::rwlock::{RwLock, RwLockReadGuard, RwLockWriteGuard};
195201

202+
#[unstable(feature = "mpmc_channel", issue = "126840")]
203+
pub mod mpmc;
196204
pub mod mpsc;
197205

198206
mod barrier;
199207
mod condvar;
200208
mod lazy_lock;
201-
mod mpmc;
202209
mod mutex;
203210
pub(crate) mod once;
204211
mod once_lock;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::{error, fmt};
77
///
88
/// [`send_timeout`]: super::Sender::send_timeout
99
#[derive(PartialEq, Eq, Clone, Copy)]
10+
#[unstable(feature = "mpmc_channel", issue = "126840")]
1011
pub enum SendTimeoutError<T> {
1112
/// The message could not be sent because the channel is full and the operation timed out.
1213
///
@@ -18,12 +19,14 @@ pub enum SendTimeoutError<T> {
1819
Disconnected(T),
1920
}
2021

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

29+
#[unstable(feature = "mpmc_channel", issue = "126840")]
2730
impl<T> fmt::Display for SendTimeoutError<T> {
2831
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2932
match *self {
@@ -33,8 +36,10 @@ impl<T> fmt::Display for SendTimeoutError<T> {
3336
}
3437
}
3538

39+
#[unstable(feature = "mpmc_channel", issue = "126840")]
3640
impl<T> error::Error for SendTimeoutError<T> {}
3741

42+
#[unstable(feature = "mpmc_channel", issue = "126840")]
3843
impl<T> From<SendError<T>> for SendTimeoutError<T> {
3944
fn from(err: SendError<T>) -> SendTimeoutError<T> {
4045
match err {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /