I'm looking for a way for release std::io::StdinLock
externally.
In the following case, two threads are spawned (not counting the main thread) named read_stdin
and ttl
.
read_stdin
is locked byhandle.read_line
and waits forread_line
to free itself.ttl
waits 2 seconds to free itself.
Is there a way to release read_stdin
when ttl
is released?
use std::io;
use std::io::BufRead;
use std::thread;
use std::time::Duration;
fn main() {
let read_stdin = thread::spawn(move || {
let mut buffer = String::new();
let stdin = io::stdin();
let mut handle = stdin.lock();
handle.read_line(&mut buffer).unwrap();
println!("{}", buffer);
});
let ttl = thread::spawn(move || {
thread::sleep(Duration::from_secs(2));
println!("end");
});
ttl.join();
read_stdin.join();
}