Skip to content

Commit

Permalink
fixed #1
Browse files Browse the repository at this point in the history
  • Loading branch information
DuckyBlender committed Jun 1, 2023
1 parent 0b9b498 commit 668f025
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::sync::atomic::{AtomicBool, Ordering};
use std::{
fs::File,
io::Write,
Expand Down Expand Up @@ -85,6 +86,9 @@ async fn main() {
&[1.0],
]);

let should_stop = Arc::new(AtomicBool::new(false));
let should_stop_clone = Arc::clone(&should_stop);

{
let mut nn = nn.lock().unwrap();
NN::randomize(&mut nn, -1.0, 1.0);
Expand Down Expand Up @@ -120,6 +124,9 @@ async fn main() {
let info_clone = Arc::clone(&info);
let _training_thread = thread::spawn(move || {
for i in 0..=EPOCH_MAX {
if should_stop_clone.load(Ordering::SeqCst) {
break;
}
{
let mut info = info_clone.lock().unwrap();
info.epoch = i;
Expand Down Expand Up @@ -161,6 +168,8 @@ async fn main() {

// Reset?
if is_key_pressed(KeyCode::R) {
// Stop the training thread
should_stop.store(true, Ordering::SeqCst);
continue 'main;
}

Expand Down

1 comment on commit 668f025

@DuckyBlender
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually #2

Please sign in to comment.