Skip to content

Commit 9cb26f7

Browse files
ibraheemdevpetrosagg
authored andcommitted
Fix race between block initialization and receiver disconnection (crossbeam-rs#1084)
1 parent 81ff802 commit 9cb26f7

File tree

1 file changed

+2
-2
lines changed
  • crossbeam-channel/src/flavors

1 file changed

+2
-2
lines changed

crossbeam-channel/src/flavors/list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ impl<T> Channel<T> {
582582
}
583583

584584
let mut head = self.head.index.load(Ordering::Acquire);
585-
let mut block = self.head.block.load(Ordering::Acquire);
585+
let mut block = self.head.block.swap(ptr::null_mut(), Ordering::AcqRel);
586586

587587
// If we're going to be dropping messages we need to synchronize with initialization
588588
if head >> SHIFT != tail >> SHIFT {
@@ -595,6 +595,7 @@ impl<T> Channel<T> {
595595
block = self.head.block.load(Ordering::Acquire);
596596
}
597597
}
598+
598599
unsafe {
599600
// Drop all messages between head and tail and deallocate the heap-allocated blocks.
600601
while head >> SHIFT != tail >> SHIFT {
@@ -623,7 +624,6 @@ impl<T> Channel<T> {
623624
}
624625
}
625626
head &= !MARK_BIT;
626-
self.head.block.store(ptr::null_mut(), Ordering::Release);
627627
self.head.index.store(head, Ordering::Release);
628628
}
629629

0 commit comments

Comments
 (0)