-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Back io::stdin with a global singleton BufferedReader #19416
Conversation
r? @aturon |
fa47a0e
to
69a9f66
Compare
@sfackler Sorry again for the delay in reviewing this -- it's been very hectic. @alexcrichton and I talked at length about this PR today, in the context of our in progress |
Cool, I was considering doing that. I see three possibilities for those.
I think the first option is probably the best for now, since if we have |
I would actually lean more toward bullet 3 (since that's rougly the behavior you'd get by repeatedly calling |
42000e2
to
22a0d72
Compare
@aturon updated |
22a0d72
to
02ce0f2
Compare
I also adjusted |
io::stdin returns a new `BufferedReader` each time it's called, which results in some very confusing behavior with disappearing output. It now returns a `StdinReader`, which wraps a global singleton `Arc<Mutex<BufferedReader<StdReader>>`. `Reader` is implemented directly on `StdinReader`. However, `Buffer` is not, as the `fill_buf` method is fundamentaly un-thread safe. A `lock` method is defined on `StdinReader` which returns a smart pointer wrapping the underlying `BufferedReader` while guaranteeing mutual exclusion. Code that treats the return value of io::stdin as implementing `Buffer` will break. Add a call to `lock`: ```rust io::stdin().lines() // => io::stdin().lock().lines() ``` Closes rust-lang#14434 [breaking-change]
02ce0f2
to
e7c1f57
Compare
Buffered reading from stdin now needs to lock stdin. This is to solve rust-lang/rust#14434 which was a race condition on buffered reads from stdin. This change is to conform to the new API submitted as part of rust-lang/rust#19416.
Buffered reading from stdin now needs to lock stdin. This is to solve rust-lang/rust#14434 which was a race condition on buffered reads from stdin. This change is to conform to the new API submitted in rust-lang/rust@e7c1f57 as part of rust-lang/rust#19416.
io::stdin returns a new
BufferedReader
each time it's called, whichresults in some very confusing behavior with disappearing output. It now
returns a
StdinReader
, which wraps a global singletonArc<Mutex<BufferedReader<StdReader>>
.Reader
is implemented directlyon
StdinReader
. However,Buffer
is not, as thefill_buf
method isfundamentaly un-thread safe. A
lock
method is defined onStdinReader
which returns a smart pointer wrapping the underlying
BufferedReader
while guaranteeing mutual exclusion.
Code that treats the return value of io::stdin as implementing
Buffer
will break. Add a call to
lock
:Closes #14434
[breaking-change]