#![feature(std_misc, io)]
use std::sync::mpsc::{sync_channel, Select};
use std::old_io::timer::{sleep};
use std::time::duration::{Duration};
use std::thread::{Thread};
fn main() {
let (snd, rcv) = sync_channel(0);
Thread::spawn(move || {
if snd.send(0u8).is_ok() {
panic!();
}
});
let select = Select::new();
let mut handle = select.handle(&rcv);
unsafe { handle.add(); }
select.wait();
sleep(Duration::milliseconds(1));
}
thread '<unnamed>' panicked at 'explicit panic', test4.rs:13
As you can see, recv is never called on rcv.
This panics because send checks if there is someone sleeping on the "notification" condvar in a BlockedReceiver variant. Select::wait adds such a variant to get notified when there is a sender.
As you can see,
recvis never called onrcv.This panics because
sendchecks if there is someone sleeping on the "notification" condvar in aBlockedReceivervariant.Select::waitadds such a variant to get notified when there is a sender.