refactored the thread loop
a thread will break if the atomic bool is true
This commit is contained in:
committed by
Michael Vines
parent
d52567933e
commit
5df0478fa3
@ -429,8 +429,6 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||||||
output_keypair(&keypair, &outfile, "recovered")?;
|
output_keypair(&keypair, &outfile, "recovered")?;
|
||||||
}
|
}
|
||||||
("grind", Some(matches)) => {
|
("grind", Some(matches)) => {
|
||||||
let mut grind_matches = Vec::<GrindMatch>::new();
|
|
||||||
|
|
||||||
let ignore_case = matches.is_present("ignore_case");
|
let ignore_case = matches.is_present("ignore_case");
|
||||||
|
|
||||||
let starts_with_args = if matches.is_present("starts_with") {
|
let starts_with_args = if matches.is_present("starts_with") {
|
||||||
@ -477,16 +475,16 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
let done = Arc::new(AtomicBool::new(false));
|
let done = Arc::new(AtomicBool::new(false));
|
||||||
|
|
||||||
let _threads = (0..num_cpus::get())
|
let _threads = 0..num_cpus::get();
|
||||||
.map(|_| {
|
for _ in _threads {
|
||||||
let done = done.clone();
|
let done = done.clone();
|
||||||
let attempts = attempts.clone();
|
let attempts = attempts.clone();
|
||||||
let found = found.clone();
|
let found = found.clone();
|
||||||
let grind_matches_thread_safe = grind_matches_thread_safe.clone();
|
let grind_matches_thread_safe = grind_matches_thread_safe.clone();
|
||||||
|
|
||||||
thread::spawn(move || loop {
|
let handle = thread::spawn(move || loop {
|
||||||
if done.load(Ordering::Relaxed) {
|
if done.load(Ordering::Relaxed) {
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
let attempts = attempts.fetch_add(1, Ordering::Relaxed);
|
let attempts = attempts.fetch_add(1, Ordering::Relaxed);
|
||||||
if attempts % 1_000_000 == 0 {
|
if attempts % 1_000_000 == 0 {
|
||||||
@ -523,10 +521,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||||||
grind_matches_thread_safe[i]
|
grind_matches_thread_safe[i]
|
||||||
.count
|
.count
|
||||||
.fetch_sub(1, Ordering::Relaxed);
|
.fetch_sub(1, Ordering::Relaxed);
|
||||||
println!(
|
println!("Wrote keypair to {}", &format!("{}.json", keypair.pubkey()));
|
||||||
"Wrote keypair to {}",
|
|
||||||
&format!("{}.json", keypair.pubkey())
|
|
||||||
);
|
|
||||||
write_keypair_file(&keypair, &format!("{}.json", keypair.pubkey()))
|
write_keypair_file(&keypair, &format!("{}.json", keypair.pubkey()))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
@ -535,9 +530,8 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||||||
done.store(true, Ordering::Relaxed);
|
done.store(true, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
handle.join().unwrap();
|
||||||
.collect::<Vec<_>>();
|
}
|
||||||
thread::park();
|
|
||||||
}
|
}
|
||||||
("verify", Some(matches)) => {
|
("verify", Some(matches)) => {
|
||||||
let keypair = get_keypair_from_matches(matches)?;
|
let keypair = get_keypair_from_matches(matches)?;
|
||||||
|
Reference in New Issue
Block a user