]> git.lizzy.rs Git - rust.git/commit
Fix an easy to trigger deadlock in std::io::stdio
authorSimonas Kazlauskas <git@kazlauskas.me>
Thu, 5 Mar 2015 21:03:30 +0000 (23:03 +0200)
committerSimonas Kazlauskas <git@kazlauskas.me>
Fri, 6 Mar 2015 09:22:07 +0000 (11:22 +0200)
commit3f94260b0fb2639ba81a5458ec54329e4b860afd
treeb6d20a006d5873fa3b9bda16eb34ac6a4c5d6f6c
parent68740b405404a3f885e388c8d31722797d519c30
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