Is StdoutLock guranteed to be reentrant? #134698
Labels
A-docs
Area: Documentation for any part of the project, including the compiler, standard library, and tools
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
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):As far as I understand, this works because
Stdout::lock()
is reentrant. However, the documentation does not mention thatStdout::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()
andStdin::lock()
.The text was updated successfully, but these errors were encountered: