Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::thread;
- use std::thread::JoinHandle;
- struct A {
- field: i32,
- th: Option<JoinHandle<()>>,
- }
- impl A {
- fn foo(&mut self) {
- self.th = Some(thread::spawn(|| {
- bar(&self.field);
- }));
- }
- }
- impl Drop for A {
- fn drop(&mut self) {
- self.th.unwrap().join();
- }
- }
- fn bar(_: &i32) {}
Add Comment
Please, Sign In to add comment