From 22e7013e2d2d4800a9e82024d2274730bdc08712 Mon Sep 17 00:00:00 2001 From: trivernis Date: Wed, 29 Jan 2020 10:43:03 +0100 Subject: [PATCH] Add extended debug logging to check on threads --- .idea/discord.xml | 9 --------- src/main.rs | 20 ++++++++++++-------- 2 files changed, 12 insertions(+), 17 deletions(-) delete mode 100644 .idea/discord.xml diff --git a/.idea/discord.xml b/.idea/discord.xml deleted file mode 100644 index 59b11d1..0000000 --- a/.idea/discord.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 5171e1c..07d0986 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,11 @@ +use may::go; +use may::sync::mpmc::{channel, Sender}; use num_cpus; -use std::fs::{OpenOptions}; -use std::io::prelude::*; use std::env; -use std::time::{Instant}; +use std::fs::OpenOptions; +use std::io::prelude::*; use std::io::BufWriter; -use may::sync::mpmc::{channel, Sender}; -use may::go; +use std::time::Instant; fn main() { may::config().set_workers(num_cpus::get()); @@ -40,7 +40,10 @@ fn main() { let prime = rx.recv().unwrap(); prime_count += 1; println!("\r{: <30}", prime); - print!("{} Primes/s", prime_count as f64/time_start.elapsed().as_secs_f64()); + print!( + "{} Primes/s", + prime_count as f64 / time_start.elapsed().as_secs_f64() + ); if let Err(e) = buffer.write(&format!("{}\n", prime).into_bytes()) { panic!(e); } @@ -48,6 +51,7 @@ fn main() { } fn get_primes(start: u64, incr: u64, tx: &Sender) { + println!("Hi, I'm a thread."); let mut num = start; loop { let mut is_prime = true; @@ -55,7 +59,7 @@ fn get_primes(start: u64, incr: u64, tx: &Sender) { num += incr; continue; } - for i in (3u64..&num/2).step_by(2) { + for i in (3u64..&num / 2).step_by(2) { if num % i == 0 { is_prime = false; } @@ -65,4 +69,4 @@ fn get_primes(start: u64, incr: u64, tx: &Sender) { } num += incr; } -} \ No newline at end of file +}