mirror of
https://github.com/xythrez/RustMP.git
synced 2025-09-04 21:52:36 +00:00
Removed imports for multiple calls to par_for!, renamed variables to
avoid clashing, added blocksize parameter
This commit is contained in:
parent
bb1391b8b2
commit
e23b39ee41
3 changed files with 50 additions and 33 deletions
|
@ -12,7 +12,7 @@ struct Student {
|
|||
impl Student {
|
||||
pub fn new(age: u8) -> Student {
|
||||
Student { name: "Default".to_string(),
|
||||
age: age,
|
||||
age,
|
||||
gpa: age as f32 }
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,7 @@ fn main() {
|
|||
let numbers: Vec<Student> = vec![];
|
||||
|
||||
par_for! {
|
||||
for i in 1..10, capturing numbers {
|
||||
|
||||
for i in 1..32, capturing numbers {
|
||||
//std::thread::sleep(
|
||||
// time::Duration::from_secs(
|
||||
// rand::thread_rng().gen_range(1..10)));
|
||||
|
@ -31,6 +30,13 @@ fn main() {
|
|||
println!("Thread {} running!", i);
|
||||
} };
|
||||
|
||||
par_for! {
|
||||
for i in 1..32, blocksize 16, capturing numbers {
|
||||
let mut lock = numbers.write();
|
||||
lock.push(Student::new(i));
|
||||
println!("Thread {} running!", i);
|
||||
} };
|
||||
|
||||
for num in numbers {
|
||||
println!("{:?}", num);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue