error[E0507]: cannot move out of `loaderthread`, a captured variable in an `FnMut` closure
--> src/main.rs:470:13
|
278 | let loaderthread = start_content_thread(
| ------------ captured outer variable
...
470 | loaderthread.join(); // wait for loader thread
| ^^^^^^^^^^^^ move occurs because `loaderthread` has type `std::thread::JoinHandle<()>`, which does not implement the `Copy` trait
error: aborting due to previous error
For more information about this error, try `rustc --explain E0507`.
error: could not compile `worldviewer`
This is a cute little problem. I have a windowed program with a "winit" event loop. Winit event loops, which are closures, never return; they just exit, So any cleanup must take place withing the event loop when handing the exit event. The event loop starts like this:
event_loop.run(move |event, _window_target, control| match event {
I also have another thread running, launched at "let loaderthread = start_content_thread()". "loaderthread", a JoinHandle, is created outside the event loop, and then captured by the event loop closure. Inside the event loop closure, I tell the thread to quit via a flag, and then do a join, waiting for it to finish, clean up, and exit.
Can't do that. See error above. Normally, that would just be a move of JoinHandle into the closure, but that doesn't work here.
Can't copy a JoinHandle.
Boxing loaderthread yields:
error[E0507]: cannot move out of `*loaderthread`, as `loaderthread` is a captured variable in an `FnMut` closure
--> src/main.rs:471:13
|
279 | let loaderthread = Box::new(start_content_thread(
| ------------ captured outer variable
...
471 | loaderthread.join(); // wait for loader thread
| ^^^^^^^^^^^^ move occurs because `*loaderthread` has type `std::thread::JoinHandle<()>`, which does not implement the `Copy` trait
Any ideas?