diff options
Diffstat (limited to 'azalea/examples')
| -rw-r--r-- | azalea/examples/testbot/main.rs | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/azalea/examples/testbot/main.rs b/azalea/examples/testbot/main.rs index e7d68d5e..9c8d1085 100644 --- a/azalea/examples/testbot/main.rs +++ b/azalea/examples/testbot/main.rs @@ -14,8 +14,8 @@ mod commands; pub mod killaura; -use std::sync::Arc; use std::time::Duration; +use std::{sync::Arc, thread}; use azalea::brigadier::command_dispatcher::CommandDispatcher; use azalea::ecs::prelude::*; @@ -37,30 +37,7 @@ const PATHFINDER_DEBUG_PARTICLES: bool = false; #[tokio::main] async fn main() { - { - use std::thread; - use std::time::Duration; - - use parking_lot::deadlock; - - // Create a background thread which checks for deadlocks every 10s - thread::spawn(move || loop { - thread::sleep(Duration::from_secs(10)); - let deadlocks = deadlock::check_deadlock(); - if deadlocks.is_empty() { - continue; - } - - println!("{} deadlocks detected", deadlocks.len()); - for (i, threads) in deadlocks.iter().enumerate() { - println!("Deadlock #{i}"); - for t in threads { - println!("Thread Id {:#?}", t.thread_id()); - println!("{:#?}", t.backtrace()); - } - } - }); - } + thread::spawn(deadlock_detection_thread); let account = Account::offline(USERNAME); @@ -85,6 +62,30 @@ async fn main() { .unwrap(); } +/// Runs a loop that checks for deadlocks every 10 seconds. +/// +/// Note that this requires the `deadlock_detection` parking_lot feature to be +/// enabled, which is only enabled in azalea by default when running in debug +/// mode. +fn deadlock_detection_thread() { + loop { + thread::sleep(Duration::from_secs(10)); + let deadlocks = parking_lot::deadlock::check_deadlock(); + if deadlocks.is_empty() { + continue; + } + + println!("{} deadlocks detected", deadlocks.len()); + for (i, threads) in deadlocks.iter().enumerate() { + println!("Deadlock #{i}"); + for t in threads { + println!("Thread Id {:#?}", t.thread_id()); + println!("{:#?}", t.backtrace()); + } + } + } +} + #[derive(Clone, Copy, Debug, PartialEq, Eq, Default)] pub enum BotTask { #[default] |
