-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Closed
Description
I didn't check if this has been reported yet, but there seems to be an inconsistency in the runtime system at program termination.
I slightly modified the channels example from rust's tutorial:
use std::comm::DuplexStream;
use std::comm::duplex;
fn stringifier (channel: &DuplexStream<String, uint>) {
let mut value: uint;
loop {
value = channel.recv();
channel.send(value.to_str());
// KEEP THREAD RUNNING DURING PROGRAM TERMINATION
// if value == 0 { break; }
}
}
fn main () {
let (from_child, to_child) = duplex();
spawn(proc() {
stringifier(&to_child);
});
from_child.send(22);
assert!(from_child.recv().as_slice() == "22");
from_child.send(23);
from_child.send(0);
assert!(from_child.recv().as_slice() == "23");
assert!(from_child.recv().as_slice() == "0");
println! ("everything ok");
}
The program output is this:
everything ok
task '<unnamed>' failed at 'receiving on a closed channel', /home/rustbuild/src/rust-buildbot/slave/dist2-linux/build/src/libsync/comm/mod.rs:806
It seems to me, that during program termination, it is safe to kill everything listening on some channel before closing it, not afterwards, thus avoiding above error. Or does the ordering of the shutdown serve some purpose I overlooked?
BTW I'm using the following build
rustc 0.11.0 (aa1163b92de7717eb7c5eba002b4012e0574a7fe 2014-06-27 12:50:16 -0700)
Metadata
Metadata
Assignees
Labels
No labels