Skip to content

Commit

Permalink
Add more nuanced advice about spin_loop_hint
Browse files Browse the repository at this point in the history
  • Loading branch information
matklad committed Jan 5, 2020
1 parent 4d04b0b commit b25eeef
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/libcore/sync/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit b25eeef

Please sign in to comment.