# Function std::thread::yield_now 1.0.0[−][src]

    pub fn yield_now()

Cooperatively gives up a timeslice to the OS scheduler.

This is used when the programmer knows that the thread will have nothing to do for some time, and thus avoid wasting computing time.

For example when polling on a resource, it is common to check that it is available, and if not to yield in order to avoid busy waiting.

Thus the pattern of `yield`ing after a failed poll is rather common when implementing low-level shared resources or synchronization primitives.

However programmers will usually prefer to use, `channel`s, `Condvar`s, `Mutex`es or `join` for their synchronization routines, as they avoid thinking about thread scheduling.

Note that `channel`s for example are implemented using this primitive. Indeed when you call `send` or `recv`, which are blocking, they will yield if the channel is not available.

# Examples

    use std::thread;

    thread::yield_now();Run

# 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`)