0db060cfd0 | ||
---|---|---|
.github | ||
src | ||
tests | ||
.gitignore | ||
CHANGELOG.md | ||
Cargo.toml | ||
LICENSE-APACHE | ||
LICENSE-MIT | ||
README.md |
README.md
easy-parallel
Easy parallel closures.
This is a simple primitive for spawning threads in bulk and waiting for them to complete. Threads are allowed to borrow local variables from the main thread.
Examples
Run two threads that increment a number:
use easy_parallel::Parallel;
use std::sync::Mutex;
let mut m = Mutex::new(0);
Parallel::new()
.add(|| *m.lock().unwrap() += 1)
.add(|| *m.lock().unwrap() += 1)
.run();
assert_eq!(*m.get_mut().unwrap(), 2);
Print each number in a vector on a different thread:
use easy_parallel::Parallel;
let mut v = vec![10, 20, 30];
Parallel::new()
.each(0..v.len(), |i| println!("{}", v[i]))
.run();
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.