panic_monitor

Crates.iopanic_monitor
lib.rspanic_monitor
version0.2.1
sourcesrc
created_at2018-05-02 04:38:48.278231
updated_at2018-05-02 04:38:48.278231
descriptionhelps you monitor your threads and deal with panics
homepage
repositoryhttps://github.com/asayers/panic_monitor
max_upload_size
id63363
size23,495
CI (github:colearn-dev:ci)

documentation

https://docs.rs/panic_monitor/

README

                             =============
                             panic_monitor
                             =============

panic_monitor helps you monitor your threads and deal with panics. You might be tempted to use libstd's JoinHandles for this use-case; however, they have two major limitations:

  • JoinHandle::join() blocks the current thread. If you want to monitor multiple threads from a single "watchdog" thread, you need something like try_join(), and ideally you'd have an "epoll for JoinHandles" to avoid busy-waiting. JoinHandle doesn't implement these, however.
  • You can't clone a JoinHandle. If you want multiple threads to be notified when a particular thread panics, you can't use its JoinHandle to achieve it.

panic_monitor solves both of these issues. PanicMonitor::wait() allows you to specify a number of threads, and it returns as soon as one of them panics. Threads are specified by their ThreadId (which is clonable), meaning that mulitple threads can monitor the same thread. Each call to PanicMonitor::wait() can specify a different set of watched threads.

When a watched thread panics, you get a Thread struct back (which contains the thread's name and ID). In contrast with JoinHandle::join(), you don't get the value which was passed to panic!() - this is not possible, given that this value is not required to implement Clone.

LICENCE

Licensed under either of the following, at your option:

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Commit count: 20

cargo fmt