From 580b003edd9653201583df2944875a3605739f96 Mon Sep 17 00:00:00 2001 From: Ibraheem Ahmed Date: Mon, 26 Feb 2024 13:53:35 -0500 Subject: [PATCH] fix race between block initialization and receiver disconnection --- library/std/src/sync/mpmc/list.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/sync/mpmc/list.rs b/library/std/src/sync/mpmc/list.rs index 406a331a309..a1b275112a1 100644 --- a/library/std/src/sync/mpmc/list.rs +++ b/library/std/src/sync/mpmc/list.rs @@ -547,7 +547,7 @@ impl Channel { } 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 { @@ -588,8 +588,8 @@ impl Channel { drop(Box::from_raw(block)); } } + head &= !MARK_BIT; - self.head.block.store(ptr::null_mut(), Ordering::Release); self.head.index.store(head, Ordering::Release); }