Go to file
Stjepan Glavina 1882f805d4 More examples 2020-05-27 12:26:44 +02:00
.github Initial commit 2020-05-27 00:05:45 +02:00
examples More examples 2020-05-27 12:26:44 +02:00
src More examples 2020-05-27 12:26:44 +02:00
tests Collect results in run() 2020-05-27 10:08:25 +02:00
.gitignore Initial commit 2020-05-27 00:05:45 +02:00
CHANGELOG.md Bump to v2.0.0 2020-05-27 10:10:37 +02:00
Cargo.toml Bump to v2.0.0 2020-05-27 10:10:37 +02:00
LICENSE-APACHE Initial commit 2020-05-27 00:05:45 +02:00
LICENSE-MIT Initial commit 2020-05-27 00:05:45 +02:00
README.md Bump to v2.0.0 2020-05-27 10:10:37 +02:00

README.md

easy-parallel

Build License Cargo Documentation

Run closures in parallel.

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);

Square each number of a vector on a different thread:

use easy_parallel::Parallel;

let v = vec![10, 20, 30];

let mut squares = Parallel::new()
    .each(0..v.len(), |i| v[i] * v[i])
    .run();

squares.sort();
assert_eq!(squares, [100, 400, 900]);

License

Licensed under either of

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.