From 4e9e465bd4cbdfe3946ea6f0ff4786f2f495a020 Mon Sep 17 00:00:00 2001 From: joboet Date: Sun, 26 Feb 2023 11:57:27 +0100 Subject: [PATCH] std: disconnect senders before discarding messages --- library/std/src/sync/mpmc/array.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/library/std/src/sync/mpmc/array.rs b/library/std/src/sync/mpmc/array.rs index 7038176000362..fb893695a9a58 100644 --- a/library/std/src/sync/mpmc/array.rs +++ b/library/std/src/sync/mpmc/array.rs @@ -464,14 +464,15 @@ impl Channel { /// ordering or stronger. pub(crate) unsafe fn disconnect_receivers(&self) -> bool { let tail = self.tail.fetch_or(self.mark_bit, Ordering::SeqCst); - self.discard_all_messages(tail); - - if tail & self.mark_bit == 0 { + let disconnected = if tail & self.mark_bit == 0 { self.senders.disconnect(); true } else { false - } + }; + + self.discard_all_messages(tail); + disconnected } /// Discards all messages.