Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::sync::{Mutex, mpsc::{self, Sender}};
- use std::thread;
- use std::time::Duration;
- struct MySender(::std::sync::mpsc::Sender<()>);
- impl Clone for MySender {
- fn clone(&self) -> Self {
- println!("clone");
- MySender(self.0.clone())
- }
- }
- impl Drop for MySender {
- fn drop(&mut self) {
- println!("Drop");
- }
- }
- fn main() {
- let mutex = Mutex::new(());
- let (tx, rx) = mpsc::channel();
- let tx = MySender(tx);
- thread::spawn(move || {
- let _ = tx.clone();
- thread::sleep(Duration::from_secs(5));
- });
- println!("first read");
- let _ = rx.recv_timeout(Duration::from_millis(500));
- println!("second read");
- let _ = rx.recv_timeout(Duration::from_millis(500));
- }
Add Comment
Please, Sign In to add comment