diff --git a/src/channel/mpmc.rs b/src/channel/mpmc.rs index 88a9dbe..9125fd8 100644 --- a/src/channel/mpmc.rs +++ b/src/channel/mpmc.rs @@ -1070,6 +1070,16 @@ mod if_alloc { } } + // The stream is thread-safe as long as a thread-safe mutex is used + // and the inner future cannot be accessed by a shared reference. + unsafe impl Sync + for SharedStream + where + A: RingBuf, + { + } + + // Export parking_lot based shared channels in std mode #[cfg(feature = "std")] mod if_std { diff --git a/tests/mpmc_channel.rs b/tests/mpmc_channel.rs index c9d7fe3..e4297f6 100644 --- a/tests/mpmc_channel.rs +++ b/tests/mpmc_channel.rs @@ -1135,6 +1135,13 @@ mod if_std { is_send(&send_fut); } + #[test] + fn shared_channel_stream_is_sync() { + let (_, receiver) = channel::(1); + let stream = receiver.into_stream(); + is_sync(&stream); + } + // Check if SharedChannel can be used in traits pub trait StreamTrait { type Output;