Struct collective::thread::monitor::ThreadMonitor
source · pub struct ThreadMonitor { /* private fields */ }
Expand description
A thread panic monitor.
Implementations§
source§impl ThreadMonitor
impl ThreadMonitor
sourcepub fn init(&'static self) -> Result<()>
pub fn init(&'static self) -> Result<()>
Initializes the thread monitor.
This should be done before watching any threads.
Internally, the monitor will set up a new panic hook, which will be used for detecting panics on the threads being watched.
The monitor will initially ignore all panics. Use set_watched
or
watch
to specify which threads to monitor.
sourcepub fn set_watched(&self, thread_ids: HashSet<ThreadId>) -> Result<()>
pub fn set_watched(&self, thread_ids: HashSet<ThreadId>) -> Result<()>
Set the threads to be watched by this monitor.
If ThreadMonitor::init
has been called, the monitor will begin
recording panics for the specified threads.
sourcepub fn watch(
&self,
thread_ids: Option<&HashSet<ThreadId>>
) -> Result<Vec<Thread>>
pub fn watch(
&self,
thread_ids: Option<&HashSet<ThreadId>>
) -> Result<Vec<Thread>>
Watches the provided thread IDs.
ThreadMonitor::init
has to be called before this method. An
Uninitialized
error will be returned if it’s not.
- If an empty set is passed, this function returns immediately.
- If a thread set is not passed and one hasn’t been set with
set_watched
, aNoWatches
error will be returned. - If
set_watched
was previously called and one of the watched threads already panicked, this function will return immediately. - Otherwise, the monitor will block the current thread until one of the watched threads has a panic.