master
Andrew Johnson 6 years ago
parent b56f5b1c25
commit 188313d520

@ -5,6 +5,8 @@ version = "1.0.0"
[dependencies]
nix = "0.10"
thread-id = "3.3"
lazy_static = "1.0"
rand = "0.4.2"
[[bin]]
name = "process_a"
@ -41,3 +43,7 @@ path = "thread3.rs"
[[bin]]
name = "thread4"
path = "thread4.rs"
[[bin]]
name = "thread5"
path = "thread5.rs"

@ -0,0 +1,46 @@
use std::{thread,time};
extern crate rand;
use std::sync::{Arc,Mutex};
#[macro_use] extern crate lazy_static;
lazy_static! {
static ref NEURAL_NET_WEIGHTS: Vec<Arc<Mutex<Vec<f64>>>> = {
let mut nn = Vec::with_capacity(10000);
for _ in 0..10000 {
let mut mm = Vec::with_capacity(100);
for _ in 0..100 {
mm.push(rand::random::<f64>());
}
let mm = Arc::new(Mutex::new(mm));
nn.push(mm);
}
nn
};
}
fn train() {
let t = time::Duration::from_millis(100);
loop {
for _ in 0..100 {
let update_position = rand::random::<u64>() % 1000000;
let update_column = update_position / 10000;
let update_row = update_position % 100;
let update_value = rand::random::<f64>();
let mut update_column = NEURAL_NET_WEIGHTS[update_column as usize].lock().unwrap();
update_column[update_row as usize] = update_value;
}
thread::sleep(t);
}
}
fn main() {
let t = time::Duration::from_millis(1000);
for _ in 0..500 {
thread::spawn(train);
}
loop {
thread::sleep(t);
}
}
Loading…
Cancel
Save