| 296 | |
| 297 | impl Drop for CpuRuntime { |
| 298 | fn drop(&mut self) { |
| 299 | // Notify the thread to shutdown. |
| 300 | self.notify_shutdown.notify_one(); |
| 301 | // In a production system you also need to ensure your code stops adding |
| 302 | // new tasks to the underlying runtime after this point to allow the |
| 303 | // thread to complete its work and exit cleanly. |
| 304 | if let Some(thread_join_handle) = self.thread_join_handle.take() { |
| 305 | // If the thread is still running, we wait for it to finish |
| 306 | print!("Shutting down CPU runtime thread..."); |
| 307 | if let Err(e) = thread_join_handle.join() { |
| 308 | eprintln!("Error joining CPU runtime thread: {e:?}",); |
| 309 | } else { |
| 310 | println!("CPU runtime thread shutdown successfully."); |
| 311 | } |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | impl CpuRuntime { |