Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use rayon::prelude::*; // 1.1.0
- use parking_lot::Mutex; // 0.9.0
- fn main() {
- let vecs = vec![
- Mutex::new(vec![1, 2, 3]),
- Mutex::new(vec![1, 2, 3]),
- Mutex::new(vec![1, 2, 3]),
- Mutex::new(vec![1, 2, 3]),
- Mutex::new(vec![1, 2, 3]),
- Mutex::new(vec![1, 2, 3]),
- ];
- let mut indices = vec![4, 3, 1];
- // Ensure all indices are unique to ensure safety:
- indices.sort_unstable();
- let len = indices.len();
- indices.dedup();
- assert!(indices.len() == len);
- indices.par_iter().for_each(|index| {
- vecs[*index].try_lock().unwrap().push(4);
- });
- println!("vecs: {:?}", vecs);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement