Skip to content

Commit b25eeef

Browse files
committed
Add more nuanced advice about spin_loop_hint
1 parent 4d04b0b commit b25eeef

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/libcore/sync/atomic.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,10 @@ use crate::hint::spin_loop;
134134
/// This function is different from [`std::thread::yield_now`] which directly yields to the
135135
/// system's scheduler, whereas `spin_loop_hint` does not interact with the operating system.
136136
///
137-
/// If actively spinning for a long time is required, e.g. because code polls a non-blocking API,
138-
/// calling [`std::thread::yield_now`] or [`std::thread::sleep`] may be the best option.
137+
/// A common use case for `spin_loop_hint` is implementing bounded optimistic spinning in a CAS
138+
/// loop in synchronization primitives. To avoid problems like priority inversion, it is strongly
139+
/// recommended that the spin loop is terminated after a finite amount of iterations and an
140+
/// appropriate blocking syscall is made.
139141
///
140142
/// **Note**: On platforms that do not support receiving spin-loop hints this function does not
141143
/// do anything at all.

0 commit comments

Comments
 (0)