From 98bf99e2f8cf8b357d63a67ce67d5fc5ceef8b3c Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Fri, 9 Sep 2022 13:36:26 +0200 Subject: Merge commit 'b52fb5234cd7c11ecfae51897a6f7fa52e8777fc' into clippyup --- src/docs/missing_spin_loop.txt | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/docs/missing_spin_loop.txt (limited to 'src/docs/missing_spin_loop.txt') diff --git a/src/docs/missing_spin_loop.txt b/src/docs/missing_spin_loop.txt new file mode 100644 index 00000000000..3a06a91d718 --- /dev/null +++ b/src/docs/missing_spin_loop.txt @@ -0,0 +1,27 @@ +### What it does +Check for empty spin loops + +### Why is this bad? +The loop body should have something like `thread::park()` or at least +`std::hint::spin_loop()` to avoid needlessly burning cycles and conserve +energy. Perhaps even better use an actual lock, if possible. + +### Known problems +This lint doesn't currently trigger on `while let` or +`loop { match .. { .. } }` loops, which would be considered idiomatic in +combination with e.g. `AtomicBool::compare_exchange_weak`. + +### Example + +``` +use core::sync::atomic::{AtomicBool, Ordering}; +let b = AtomicBool::new(true); +// give a ref to `b` to another thread,wait for it to become false +while b.load(Ordering::Acquire) {}; +``` +Use instead: +``` +while b.load(Ordering::Acquire) { + std::hint::spin_loop() +} +``` \ No newline at end of file -- cgit 1.4.1-3-g733a5