Guest User

Untitled

a guest
Oct 12th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  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) {}
Add Comment
Please, Sign In to add comment