mirror of https://github.com/xythrez/RustMP.git
Fixed ad_hoc parallel versions using 1 extra thread than specified.
This commit is contained in:
parent
23384f7d82
commit
31fca0b6d7
|
@ -78,6 +78,9 @@ fn rmp_main() {
|
|||
}
|
||||
}
|
||||
|
||||
// Startup - Extract the thread's own iterator
|
||||
let __rmp_internal_iter_self = __rmp_internal_iter_arr.remove(0);
|
||||
|
||||
// Execution - Spawn threads with loop contents
|
||||
for __rmp_internal_iter in __rmp_internal_iter_arr {
|
||||
// Clone used Arcs here
|
||||
|
@ -96,6 +99,12 @@ fn rmp_main() {
|
|||
}));
|
||||
}
|
||||
|
||||
// Execution - Extract the same thread logic for self
|
||||
for i in __rmp_internal_iter_self {
|
||||
println!("Index {}: Hello from loop {}!", __rmp_var_counter.load(Ordering::SeqCst), i);
|
||||
__rmp_var_counter.fetch_add(1, Ordering::SeqCst);
|
||||
}
|
||||
|
||||
// Cleanup - Wait for threads
|
||||
for __rmp_internal_thread in __rmp_internal_threads_arr {
|
||||
let _ = __rmp_internal_thread.join();
|
||||
|
@ -114,13 +123,15 @@ fn par_main() {
|
|||
let counter = Arc::new(AtomicIsize::new(0));
|
||||
let mut children = vec![];
|
||||
|
||||
for i in 0..4 {
|
||||
for i in 1..4 {
|
||||
let counter = Arc::clone(&counter);
|
||||
children.push(thread::spawn(move || {
|
||||
let index = counter.fetch_add(1, Ordering::SeqCst);
|
||||
println!("Index {}: Hello from loop {}!", index, i);
|
||||
}));
|
||||
}
|
||||
let index = counter.fetch_add(1, Ordering::SeqCst);
|
||||
println!("Index {}: Hello from loop {}!", index, 0);
|
||||
|
||||
for child in children {
|
||||
let _ = child.join();
|
||||
|
|
Loading…
Reference in New Issue