From 8dddb2294310ad3e8ce0b2af735a702ad72a9a99 Mon Sep 17 00:00:00 2001 From: Ibraheem Ahmed Date: Mon, 17 Oct 2022 19:31:15 -0400 Subject: [PATCH] `sync::mpsc`: quadratic backoff --- library/std/src/sync/mpmc/utils.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/library/std/src/sync/mpmc/utils.rs b/library/std/src/sync/mpmc/utils.rs index 3f0cb848cc5ce..85cf5dd244139 100644 --- a/library/std/src/sync/mpmc/utils.rs +++ b/library/std/src/sync/mpmc/utils.rs @@ -110,7 +110,8 @@ impl Backoff { /// progress. #[inline] pub fn spin(&self) { - for _ in 0..1 << self.step.get().min(SPIN_LIMIT) { + let step = self.step.get().min(SPIN_LIMIT); + for _ in 0..step.pow(2) { crate::hint::spin_loop(); } @@ -123,7 +124,7 @@ impl Backoff { #[inline] pub fn snooze(&self) { if self.step.get() <= SPIN_LIMIT { - for _ in 0..1 << self.step.get() { + for _ in 0..self.step.get().pow(2) { crate::hint::spin_loop() } } else {