[−][src]Crate managed_thread
The goal of this library is to allow you to create worker threads, whilst being confident that they will be cleaned up again and you don't "leak" threads.
This is achieved by passing a Signal object to the newly spawned thread. The thread is responsible for checking this signal for whether it should terminate or not.
Therefore this library's concept is not 100% foolproof. Due to the nature of threads, there is no way in Rust to forcibly terminating a thread. So we rely on the thread to be wellbehaved and terminate if asked to do so.
use managed_thread; // channel to communicate back to main thread let (tx, rx) = std::sync::mpsc::channel::<()>(); let owned_thread = managed_thread::spawn_owned(move |signal| { while signal.should_continue() { // do some work } // Send a signal that this thread is exiting tx.send(()) }); // The owned thread will now terminate drop(owned_thread); // confirm that the managed_thread has terminated rx.recv().unwrap();
Structs
OwnedThread | The |
Signal | The signal type that is passed to the thread. |
Functions
spawn_owned | The main function of this library. |