about summary refs log tree commit diff
path: root/src/libstd/sys/unix/stack_overflow.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-03-06 15:37:47 -0800
committerAlex Crichton <alex@alexcrichton.com>2015-03-06 15:37:47 -0800
commit697de42f69c6c437b7bd7a3298e991d1a5fc9adc (patch)
tree8392a9ff4cdd4eeff55eeeb881f99a9f59bfe440 /src/libstd/sys/unix/stack_overflow.rs
parent2bd02ca83737e66ef004673373709fdc9ad9255d (diff)
parent3f94260b0fb2639ba81a5458ec54329e4b860afd (diff)
downloadrust-697de42f69c6c437b7bd7a3298e991d1a5fc9adc.tar.gz
rust-697de42f69c6c437b7bd7a3298e991d1a5fc9adc.zip
rollup merge of #23087: nagisa/std-undeadlock
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!

r? @alexcrichton

---

Either way, I find flushing stdout when stdin is used debatable. I believe people who write prompts should take care to flush stdout when necessary themselves.

Another idea: Would be cool if locks on std handles would be taken for a thread, rather than a handle, so given preamble (first code snippet)

    stdin.lock()

or more generally

    stdin.read(…)

worked fine. I.e. if more than a single lock are all taken inside the same thread, it would work, though not sure if our synchronisation primitives are expressive enough to make it possible.
Diffstat (limited to 'src/libstd/sys/unix/stack_overflow.rs')
0 files changed, 0 insertions, 0 deletions