Is StdoutLock guranteed to be reentrant?
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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