rust-lang / rust-lang/rust

`std::thread::yield_now()` example is lacking.

Open
#134,723 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-docs C-discussion T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Location

rust/library/std/src/thread/mod.rs:755

/// # Examples
///
/// ```
/// use std::thread;
///
/// thread::yield_now();
/// ```
Summary

It's not great, ideally it should show a mostly real use case.

It should maybe hint that this should not be used directly to create spin loops without first considering std::hint::spin_loop

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at rust/library/std/src/thread/mod.rs:755 and read the existing std:🧵:yield_now documentation and example. Replace the minimal call with a mostly real use case, and explain that yield_now should not be used directly to create spin loops without considering std::hint::spin_loop. Done means the example and guidance are clearer and remain valid Rust documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.