You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rayon does not handle mutex like I thought it did. Occassionally results in the program deadlocking when running through a parallel iterator if that iterator is altering a mutex: rayon-rs/rayon#592
// Create condensed links sender and receiver, avoiding use of mutex
let (condensed_links_s, condensed_links_r) = channel();
// extend the links for each anchor point by the union of all the indices
links.par_iter().for_each_with(condensed_links_s, |s, (_, current_links)|{
let mut anchors = current_links.clone();
current_links.iter().for_each(|index| {
match links.get(&index) {
Some(other_links) => {
anchors.par_extend(other_links.par_iter())
},
_ => {},
}
});
s.send(anchors).unwrap();
});
// Collect receiver into hashset
let condensed_links: HashSet<_> = condensed_links_r.iter().collect();
Issues 😢
Any HashMap types that are Arc<Mutex<_>> will be difficult to send through channel(). Not sure how to do that yet.
The text was updated successfully, but these errors were encountered:
Bug 🐛
Rayon does not handle mutex like I thought it did. Occassionally results in the program deadlocking when running through a parallel iterator if that iterator is altering a mutex: rayon-rs/rayon#592
Fix 🛠️
Refer to rayon documentation here: https://docs.rs/rayon/1.3.1/rayon/iter/trait.ParallelIterator.html#method.for_each_with
Instead of using Mutex, use
channel()
fromstd::sync
like so:Issues 😢
Any
HashMap
types that areArc<Mutex<_>>
will be difficult to send throughchannel()
. Not sure how to do that yet.The text was updated successfully, but these errors were encountered: