about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAleksey Kladov <aleksey.kladov@gmail.com>2020-01-05 20:06:52 +0100
committerAleksey Kladov <aleksey.kladov@gmail.com>2020-01-05 20:37:22 +0100
commitb25eeef88d55a412c0e0bec7c0989d5a7969f195 (patch)
treef15dcc91996f8734309de52ea6ba4acfcac5296b
parent4d04b0b0fe16dbf2227b308907bc2652be4c7c95 (diff)
downloadrust-b25eeef88d55a412c0e0bec7c0989d5a7969f195.tar.gz
rust-b25eeef88d55a412c0e0bec7c0989d5a7969f195.zip
Add more nuanced advice about spin_loop_hint
-rw-r--r--src/libcore/sync/atomic.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/libcore/sync/atomic.rs b/src/libcore/sync/atomic.rs
index ba41cd2b7a0..fae95ca5cdb 100644
--- a/src/libcore/sync/atomic.rs
+++ b/src/libcore/sync/atomic.rs
@@ -134,8 +134,10 @@ use crate::hint::spin_loop;
 /// This function is different from [`std::thread::yield_now`] which directly yields to the
 /// system's scheduler, whereas `spin_loop_hint` does not interact with the operating system.
 ///
-/// If actively spinning for a long time is required, e.g. because code polls a non-blocking API,
-/// calling [`std::thread::yield_now`] or [`std::thread::sleep`] may be the best option.
+/// A common use case for `spin_loop_hint` is implementing bounded optimistic spinning in a CAS
+/// loop in synchronization primitives. To avoid problems like priority inversion, it is strongly
+/// recommended that the spin loop is terminated after a finite amount of iterations and an
+/// appropriate blocking syscall is made.
 ///
 /// **Note**: On platforms that do not support receiving spin-loop hints this function does not
 /// do anything at all.