use std::thread;
use std::time::{Duration};
use std::sync::mpsc;
fn main() {
let (send1,rev1) = mpsc::channel();
let (send2,rev2) = mpsc::channel();
println!("Hello World!");
thread::spawn(move||{
for i in 0..5{
println!("msg out from thread0 {} ",i);
send1.send("this is th warning." ).unwrap();
let msg1 = rev2.recv_timeout(Duration::from_millis(20));
match msg1{
Ok(s)=>{println!("{}",s);},
Err(e)=>{println!("{}",e);}
}
thread::sleep(Duration::from_millis(100));
}
}
);
thread::spawn(move||{
for i in 0..50{
println!("-- {} ",i);
thread::sleep(Duration::from_millis(10));
let msg1 = rev1.recv_timeout(Duration::from_millis(1));
match msg1{
Ok(s)=>{println!("I get {}",s);
println!("》》 {} ",s);
send2.send("ack").unwrap();
},
Err(e)=>println!("{}",e)
}
}
}
);
let mut a:u32 = 0;
loop{
thread::sleep(Duration::from_millis(200));
a+=1;
if a>10{
break;
}
}
}
--
FROM 114.254.0.*