Guest User

Untitled

a guest
Apr 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. use std::sync::{Mutex, mpsc::{self, Sender}};
  2. use std::thread;
  3. use std::time::Duration;
  4.  
  5. struct MySender(::std::sync::mpsc::Sender<()>);
  6.  
  7. impl Clone for MySender {
  8. fn clone(&self) -> Self {
  9. println!("clone");
  10. MySender(self.0.clone())
  11. }
  12. }
  13.  
  14. impl Drop for MySender {
  15. fn drop(&mut self) {
  16. println!("Drop");
  17. }
  18. }
  19.  
  20. fn main() {
  21. let mutex = Mutex::new(());
  22. let (tx, rx) = mpsc::channel();
  23. let tx = MySender(tx);
  24. thread::spawn(move || {
  25. let _ = tx.clone();
  26. thread::sleep(Duration::from_secs(5));
  27. });
  28. println!("first read");
  29. let _ = rx.recv_timeout(Duration::from_millis(500));
  30. println!("second read");
  31. let _ = rx.recv_timeout(Duration::from_millis(500));
  32. }
Add Comment
Please, Sign In to add comment