Added sysinfo and included usage example

This commit is contained in:
Jack Yu 2021-04-17 15:38:15 -04:00
commit 25e0917fdd
4 changed files with 145 additions and 13 deletions

View file

@ -1,5 +1,6 @@
use rand::Rng;
use rustmp::par_for;
use rustmp::SystemObject;
use std::time;
#[derive(Debug)]
@ -11,9 +12,9 @@ struct Student {
impl Student {
pub fn new(age: u8) -> Student {
Student { name: "Default".to_string(),
age: age,
gpa: age as f32 }
Student { name: "Default".to_string(),
age: age,
gpa: age as f32 }
}
}
@ -22,15 +23,19 @@ fn main() {
par_for! {
for i in 1..10, capturing numbers {
std::thread::sleep(
time::Duration::from_secs(
rand::thread_rng().gen_range(1..10)));
let mut lock = numbers.write();
lock.push(Student::new(i));
println!("Thread {} running!", i);
// TODO: move this to parallel macro once tid design is finalized
SystemObject::get_instance().set_affinity(i as usize - 1)
.expect("Failed to bind thread to proc!");
std::thread::sleep(
time::Duration::from_secs(
rand::thread_rng().gen_range(1..10)));
let mut lock = numbers.write();
lock.push(Student::new(i));
println!("Thread {} running!", i);
} };
for num in numbers {
println!("{:?}", num);
println!("{:?}", num);
}
}