From 3f94260b0fb2639ba81a5458ec54329e4b860afd Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Thu, 5 Mar 2015 23:03:30 +0200 Subject: [PATCH] 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! --- src/libstd/io/stdio.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 61ad9905771a4..4027f741654b6 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -157,9 +157,6 @@ impl Read for Stdin { impl<'a> Read for StdinLock<'a> { fn read(&mut self, buf: &mut [u8]) -> io::Result { - // Flush stdout so that weird issues like a print!'d prompt not being - // shown until after the user hits enter. - drop(stdout().flush()); self.inner.read(buf) } }