std::sync::atomic::spin_loop_hint - Rust
Description: API documentation for the Rust `spin_loop_hint` fn in crate `std`.
Keywords: rust, rustlang, rust-lang, spin_loop_hint

# 1.24.0[−][src]Function std::sync::atomic::spin_loop_hint

    pub fn spin_loop_hint()

Signals the processor that it is entering a busy-wait spin-loop.

Upon receiving spin-loop signal the processor can optimize its behavior by, for example, saving power or switching hyper-threads.

This function is different than `std::thread::yield_now` which directly yields to the system's scheduler, whereas `spin_loop_hint` only signals the processor that it is entering a busy-wait spin-loop without yielding control to the system's scheduler.

Using a busy-wait spin-loop with `spin_loop_hint` is ideally used in situations where a contended lock is held by another thread executed on a different CPU and where the waiting times are relatively small. Because entering busy-wait spin-loop does not trigger the system's scheduler, no overhead for switching threads occurs. However, if the thread holding the contended lock is running on the same CPU, the spin-loop is likely to occupy an entire CPU slice before switching to the thread that holds the lock. If the contending lock is held by a thread on the same CPU or if the waiting times for acquiring the lock are longer, it is often better to use `std::thread::yield_now`.

Note: On platforms that do not support receiving spin-loop hints this function does not do anything at all.

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)