Skip to content

Commit

Permalink
std: disconnect senders before discarding messages
Browse files Browse the repository at this point in the history
  • Loading branch information
joboet committed Feb 26, 2023
1 parent 642a324 commit 4e9e465
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions library/std/src/sync/mpmc/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,14 +464,15 @@ impl<T> Channel<T> {
/// 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.
Expand Down

0 comments on commit 4e9e465

Please sign in to comment.