Rayon variable ownership

I'm a bit confused regarding the ownership system and how it works with the parallel iterators in rayon. For example:

let x = 10;
(0..100).into_par_iter().for_each(|y| {
  let z = x + y;
  println!("{}", z);
  println!("{}", x);

How is the ownership over x defined across multiple threads here??

The closure borrows from x. It doesn't own it.

1 Like

So essentialy, x is passed as a reference into the closure?


Many thanks! :smile: This clears things up

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.