Skip to content

Commit 3f94260

Browse files
committed
Fix an easy to trigger deadlock in std::io::stdio
Being a person who somehow has taken a liking to premature optimisation, my knee-jerk reaction to locking in std handles was preamble resembling following snippet: let stdout = stdout(); let lstdout = stdout.lock(); let stdin = stdin(); let lstdin = stdin.lock(); and then reading from the locked handle like this: let mut letter = [0; 1]; lstdin.read(&mut letter).unwrap(); As it is now this code will deadlock because the `read` method attempts to lock stdout as well!
1 parent 68740b4 commit 3f94260

File tree

1 file changed

+0
-3
lines changed

1 file changed

+0
-3
lines changed

src/libstd/io/stdio.rs

-3
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,6 @@ impl Read for Stdin {
157157

158158
impl<'a> Read for StdinLock<'a> {
159159
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
160-
// Flush stdout so that weird issues like a print!'d prompt not being
161-
// shown until after the user hits enter.
162-
drop(stdout().flush());
163160
self.inner.read(buf)
164161
}
165162
}

0 commit comments

Comments
 (0)