diff --git a/Cargo.toml b/Cargo.toml index c7de9d3..2560e28 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,6 @@ work-stealing = [] prefer-local = [] never-local = [] - [profile.bench] debug = true @@ -48,4 +47,5 @@ cfg-if = "1.0.0" [dev-dependencies] async-std = "1.13.0" tracing-test = "0.2.5" +tracing-tracy = "0.11.4" distaff = {path = "distaff"} diff --git a/distaff/src/heartbeat.rs b/distaff/src/heartbeat.rs index 5f523fb..733f0c0 100644 --- a/distaff/src/heartbeat.rs +++ b/distaff/src/heartbeat.rs @@ -74,10 +74,6 @@ impl HeartbeatListInner { } } - fn iter(&self) -> std::collections::btree_map::Values<'_, u64, HeartbeatSender> { - self.heartbeats.values() - } - fn notify_nth(&mut self, n: usize) { if let Some((_, heartbeat)) = self.heartbeats.iter_mut().nth(n) { heartbeat.set(); diff --git a/distaff/src/workerthread.rs b/distaff/src/workerthread.rs index b709a03..dccb48d 100644 --- a/distaff/src/workerthread.rs +++ b/distaff/src/workerthread.rs @@ -67,18 +67,20 @@ impl WorkerThread { fn run_inner(&self) { let mut job = None; 'outer: loop { - if let Some(job) = job { + if let Some(job) = job.take() { self.execute(job); } - if self.context.should_exit() { - // if the context is stopped, break out of the outer loop which - // will exit the thread. - break 'outer; - } - // no more jobs, wait to be notified of a new job or a heartbeat. - job = self.find_work_or_wait(); + while job.is_none() { + if self.context.should_exit() { + // if the context is stopped, break out of the outer loop which + // will exit the thread. + break 'outer; + } + + job = self.find_work_or_wait(); + } } } } diff --git a/examples/join.rs b/examples/join.rs index 9a2c31b..48e6073 100644 --- a/examples/join.rs +++ b/examples/join.rs @@ -4,10 +4,10 @@ use executor::util::tree::Tree; const TREE_SIZE: usize = 16; -fn join_scope() { +fn join_scope(tree_size: usize) { let pool = ThreadPool::new(); - let tree = Tree::new(TREE_SIZE, 1); + let tree = Tree::new(tree_size, 1); fn sum(tree: &Tree, node: usize, scope: &Scope) -> u32 { let node = tree.get(node); @@ -31,10 +31,10 @@ fn join_scope() { } } -fn join_pool() { +fn join_pool(tree_size: usize) { let pool = ThreadPool::new(); - let tree = Tree::new(TREE_SIZE, 1); + let tree = Tree::new(tree_size, 1); fn sum(tree: &Tree, node: usize, pool: &ThreadPool) -> u32 { let node = tree.get(node); @@ -60,10 +60,10 @@ fn join_pool() { eprintln!("sum: {sum}"); } -fn join_distaff() { +fn join_distaff(tree_size: usize) { use distaff::*; let pool = ThreadPool::new(); - let tree = Tree::new(TREE_SIZE, 1); + let tree = Tree::new(tree_size, 1); fn sum<'scope, 'env>(tree: &Tree, node: usize, scope: &'scope Scope<'scope, 'env>) -> u32 { let node = tree.get(node); @@ -81,17 +81,15 @@ fn join_distaff() { node.leaf + l + r } - for _ in 0..1000 { - let sum = pool.scope(|s| { - let sum = sum(&tree, tree.root().unwrap(), s); - sum - }); - std::hint::black_box(sum); - } + let sum = pool.scope(|s| { + let sum = sum(&tree, tree.root().unwrap(), s); + sum + }); + std::hint::black_box(sum); } -fn join_chili() { - let tree = Tree::new(TREE_SIZE, 1u32); +fn join_chili(tree_size: usize) { + let tree = Tree::new(tree_size, 1u32); fn sum(tree: &Tree, node: usize, scope: &mut chili::Scope<'_>) -> u32 { let node = tree.get(node); @@ -113,8 +111,8 @@ fn join_chili() { } } -fn join_rayon() { - let tree = Tree::new(TREE_SIZE, 1u32); +fn join_rayon(tree_size: usize) { + let tree = Tree::new(tree_size, 1u32); fn sum(tree: &Tree, node: usize) -> u32 { let node = tree.get(node); @@ -133,19 +131,34 @@ fn join_rayon() { } fn main() { - tracing_subscriber::fmt::init(); + // use tracing_subscriber::layer::SubscriberExt; + // tracing::subscriber::set_global_default( + // tracing_subscriber::registry().with(tracing_tracy::TracyLayer::default()), + // ) + // .expect("Failed to set global default subscriber"); + + let size = std::env::args() + .nth(2) + .and_then(|s| s.parse::().ok()) + .unwrap_or(TREE_SIZE); + match std::env::args().nth(1).as_deref() { - Some("scope") => join_scope(), - Some("pool") => join_pool(), - Some("chili") => join_chili(), - Some("distaff") => join_distaff(), - Some("rayon") => join_rayon(), + Some("scope") => join_scope(size), + Some("pool") => join_pool(size), + Some("chili") => join_chili(size), + Some("distaff") => join_distaff(size), + Some("rayon") => join_rayon(size), _ => { eprintln!( - "Usage: {} [scope|pool|chili|distaff|rayon]", - std::env::args().next().unwrap() + "Usage: {} [scope|pool|chili|distaff|rayon] ", + std::env::args().next().unwrap(), + TREE_SIZE ); return; } } + + eprintln!("Done!"); + // wait for user input before exiting + // std::io::stdin().read_line(&mut String::new()).unwrap(); }