Skip to content

Commit

Permalink
fix race between block initialization and receiver disconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
ibraheemdev committed Feb 25, 2024
1 parent a95d1a5 commit b955031
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crossbeam-channel/src/flavors/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ impl<T> Channel<T> {
}

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

// If we're going to be dropping messages we need to synchronize with initialization
if head >> SHIFT != tail >> SHIFT {
Expand All @@ -598,6 +598,7 @@ impl<T> Channel<T> {
block = self.head.block.load(Ordering::Acquire);
}
}

unsafe {
// Drop all messages between head and tail and deallocate the heap-allocated blocks.
while head >> SHIFT != tail >> SHIFT {
Expand Down Expand Up @@ -625,7 +626,6 @@ impl<T> Channel<T> {
}
}
head &= !MARK_BIT;
self.head.block.store(ptr::null_mut(), Ordering::Release);
self.head.index.store(head, Ordering::Release);
}

Expand Down

0 comments on commit b955031

Please sign in to comment.