Skip to content

Commit 8526c21

Browse files
Rollup merge of #111087 - ibraheemdev:patch-15, r=dtolnay
Implement `Sync` for `mpsc::Sender` `mpsc::Sender` is currently `!Sync` because the previous implementation contained an optimization where the channel started out as single-producer and was dynamically upgraded on the first clone, which relied on a unique reference to the sender. This optimization is one of the main reasons the old implementation was so complex and was removed in #93563. `mpsc::Sender` can now soundly implement `Sync`. Note for any potential confusion, this chance does *not* add MPMC behavior. This only affects the already `Send + Clone` *sender*, not *receiver*. It's technically possible to rely on the `!Sync` behavior in the same way as a `PhantomData<*mut T>`, but that seems very unlikely in practice. Either way, this change is insta-stable and needs an FCP. `@rustbot` label +T-libs-api -T-libs
2 parents cbdbd8d + a022a63 commit 8526c21

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

std/src/sync/mpsc/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ pub struct Sender<T> {
347347
#[stable(feature = "rust1", since = "1.0.0")]
348348
unsafe impl<T: Send> Send for Sender<T> {}
349349

350-
#[stable(feature = "rust1", since = "1.0.0")]
351-
impl<T> !Sync for Sender<T> {}
350+
#[stable(feature = "mpsc_sender_sync", since = "CURRENT_RUSTC_VERSION")]
351+
unsafe impl<T: Send> Sync for Sender<T> {}
352352

353353
/// The sending-half of Rust's synchronous [`sync_channel`] type.
354354
///

0 commit comments

Comments
 (0)