rust-lang / rust-lang/rust

Is StdoutLock guranteed to be reentrant?

Open
#134,698 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Location

https://doc.rust-lang.org/std/io/struct.Stdout.html#method.lock
https://doc.rust-lang.org/std/io/struct.Stderr.html#method.lock
https://doc.rust-lang.org/std/io/struct.Stdin.html#method.lock

Summary

Currently code like this is fine and a convenient way to lock stdout to prevent other threads from interrupting while printing is happening (this is especially useful when the printing happens deep inside some library/component, where StdoutLock can't be easily passed as an argument):

let stdout = io::stdout().lock();
println!("a");
println!("b");
println!("c");
drop(stdout);

As far as I understand, this works because Stdout::lock() is reentrant. However, the documentation does not mention that Stdout::lock() is reentrant.

Is Stdout::lock() guaranteed to be reentrant in all future Rust versions, or is this an implementation detail that should not be relied on?
Either way it would be nice if the documentation of Stdout::lock() made it clear what the expected behavior is and how much of it is an implementation detail.

The same question also applies to Stderr::lock() and Stdin::lock().

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 with the Stdout::lock, Stderr::lock, and Stdin::lock documentation linked in the issue, then verify whether reentrancy is a documented guarantee or only an implementation behavior. Done means the relevant documentation clearly states the expected reentrancy behavior and its stability across future Rust versions.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.