mirror of
https://github.com/xythrez/RustMP.git
synced 2025-09-04 21:52:36 +00:00
Added sysinfo and included usage example
This commit is contained in:
parent
2d7facfb2c
commit
25e0917fdd
4 changed files with 145 additions and 13 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue