Skip to content

Commit

Permalink
Auto merge of #121646 - ibraheemdev:patch-17, r=ChrisDenton
Browse files Browse the repository at this point in the history
Fix race between block initialization and receiver disconnection

Port of crossbeam-rs/crossbeam#1084. Closes #121582.
  • Loading branch information
bors committed Feb 26, 2024
2 parents 829308e + 580b003 commit fc3800f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions library/std/src/sync/mpmc/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,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 Down Expand Up @@ -588,8 +588,8 @@ impl<T> Channel<T> {
drop(Box::from_raw(block));
}
}

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 fc3800f

Please sign in to comment.