From 2feef494718009dbcb5c62ef1e58c84c36e8bcbf Mon Sep 17 00:00:00 2001 From: EightFactorial <29801334+EightFactorial@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:37:35 -0800 Subject: Disable the `deadlock_detection` feature by default (#195) * Disable the `deadlock_detection` feature by default Fixes conflicts with any packages that enable parking_lot's `send_guard` feature * move testbot deadlock detection to a function and add additional comments --------- Co-authored-by: mat --- azalea/examples/testbot/main.rs | 51 +++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 25 deletions(-) (limited to 'azalea/examples') 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] -- cgit v1.2.3