Use all cores (#8908)

This commit is contained in:
Michael Vines 2020-03-24 10:33:53 -07:00 committed by GitHub
parent 8f38bc7dc0
commit 1fd695d337
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 60 additions and 52 deletions

View File

@ -534,13 +534,14 @@ fn do_main(matches: &ArgMatches<'_>) -> Result<(), Box<dyn error::Error>> {
let start = Instant::now();
let done = Arc::new(AtomicBool::new(false));
for _ in 0..num_cpus::get() {
let thread_handles: Vec<_> = (0..num_cpus::get())
.map(|_| {
let done = done.clone();
let attempts = attempts.clone();
let found = found.clone();
let grind_matches_thread_safe = grind_matches_thread_safe.clone();
let handle = thread::spawn(move || loop {
thread::spawn(move || loop {
if done.load(Ordering::Relaxed) {
break;
}
@ -579,7 +580,10 @@ fn do_main(matches: &ArgMatches<'_>) -> Result<(), Box<dyn error::Error>> {
grind_matches_thread_safe[i]
.count
.fetch_sub(1, Ordering::Relaxed);
println!("Wrote keypair to {}", &format!("{}.json", keypair.pubkey()));
println!(
"Wrote keypair to {}",
&format!("{}.json", keypair.pubkey())
);
write_keypair_file(&keypair, &format!("{}.json", keypair.pubkey()))
.unwrap();
}
@ -587,8 +591,12 @@ fn do_main(matches: &ArgMatches<'_>) -> Result<(), Box<dyn error::Error>> {
if total_matches_found == grind_matches_thread_safe.len() {
done.store(true, Ordering::Relaxed);
}
});
handle.join().unwrap();
})
})
.collect();
for thread_handle in thread_handles {
thread_handle.join().unwrap();
}
}
("verify", Some(matches)) => {