From 3b0eec90322cc9e0dc5f845449b576f85bf2afe0 Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Mon, 22 Jul 2024 12:32:01 +0200 Subject: [PATCH] fix: benchmark now works and exits correctly --- src/bench/builtin.rs | 10 ++++++++-- src/bench/mod.rs | 8 ++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/bench/builtin.rs b/src/bench/builtin.rs index 8c19edd..e199c8c 100644 --- a/src/bench/builtin.rs +++ b/src/bench/builtin.rs @@ -2,7 +2,7 @@ use std::sync::atomic::AtomicBool; use std::sync::{Arc, Mutex, RwLock}; use std::thread::JoinHandle; -use libpt::log::info; +use libpt::log::{debug, info}; use crate::error::WResult; use crate::game::{self, GameBuilder}; @@ -76,7 +76,13 @@ where let report = self.report_shared(); let solver = self.solver(); // TODO: make this run in another thread somehow - Self::bench(n, report, solver, &builder)?; + self.bench(n, report, solver, builder)?; + debug!("finisihed the benchmark"); + Ok(()) + } + fn set_finished(&self, value: bool) -> WResult<()> { + self.finished + .store(value, std::sync::atomic::Ordering::Relaxed); Ok(()) } } diff --git a/src/bench/mod.rs b/src/bench/mod.rs index f06230d..1b251d3 100644 --- a/src/bench/mod.rs +++ b/src/bench/mod.rs @@ -1,6 +1,7 @@ use std::fmt::Debug; use std::sync::{Arc, RwLock}; +use libpt::log::debug; use rayon::prelude::*; use crate::error::WResult; @@ -46,6 +47,7 @@ where // NOTE: This is blocking, use start to let it run in another thread // FIXME: this never stops? Reports just keep getting printed fn bench( + &self, n: usize, report: Arc>, solver: SL, @@ -60,9 +62,10 @@ where .expect("error playing the game during benchmark"); report.write().expect("lock is poisoned").add(r); }); - + libpt::log::info!("finished playing games, finalizing report"); report.write().expect("lock is poisoned").finalize(); - + debug!("finalized the report"); + self.set_finished(true)?; Ok(report.read().expect("lock is poisoned").clone()) } // PERF: Somehow returning &Report would be better as we don't need to clone then @@ -70,4 +73,5 @@ where fn report_shared(&'wl self) -> Arc>; fn start(&'wl self, n: usize, builder: &'wl GameBuilder<'wl, WL>) -> WResult<()>; fn is_finished(&self) -> bool; + fn set_finished(&self, value: bool) -> WResult<()>; }