Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Oct 12th, 2018 66 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. use std::thread;
  2. use std::thread::JoinHandle;
  3.  
  4. struct A {
  5.     field: i32,
  6.     th: Option<JoinHandle<()>>,
  7. }
  8.  
  9. impl A {
  10.     fn foo(&mut self) {
  11.         self.th = Some(thread::spawn(|| {
  12.             bar(&self.field);
  13.         }));
  14.     }
  15. }
  16.  
  17. impl Drop for A {
  18.     fn drop(&mut self) {
  19.         self.th.unwrap().join();
  20.     }
  21. }
  22.  
  23. fn bar(_: &i32) {}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top