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?

Yes

Many thanks! :smile: This clears things up