-
Notifications
You must be signed in to change notification settings - Fork 219
/
helper.rs
38 lines (33 loc) · 1013 Bytes
/
helper.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use ckb_util::{parking_lot::deadlock, Condvar, Mutex};
use log::warn;
use std::sync::Arc;
use std::thread;
use std::time::Duration;
pub fn wait_for_exit() {
let exit = Arc::new((Mutex::new(()), Condvar::new()));
// Handle possible exits
let e = Arc::<(Mutex<()>, Condvar)>::clone(&exit);
let _ = ctrlc::set_handler(move || {
e.1.notify_all();
});
// Wait for signal
let mut l = exit.0.lock();
exit.1.wait(&mut l);
}
pub fn deadlock_detection() {
thread::spawn(move || loop {
thread::sleep(Duration::from_secs(10));
let deadlocks = deadlock::check_deadlock();
if deadlocks.is_empty() {
continue;
}
warn!("{} deadlocks detected", deadlocks.len());
for (i, threads) in deadlocks.iter().enumerate() {
warn!("Deadlock #{}", i);
for t in threads {
warn!("Thread Id {:#?}", t.thread_id());
warn!("{:#?}", t.backtrace());
}
}
});
}