0

It's been previously asked whether disjoint slices can be accessed by multiple threads. The answer is the crossbeam crate, which provides a lot of functionality.

Is it possible to do this without the use of a third party crate? If I have a vector or array, can I split it into multiple slices and have a different thread operate on each slice using only the features provided by the standard library?

Listerone
  • 1,381
  • 1
  • 11
  • 25
  • 1
    Maybe [this](https://stackoverflow.com/a/39928205/1411457) answer would help? – harmic Oct 18 '19 at 06:16
  • Possible duplicate of [Can different threads write to different sections of the same Vec?](https://stackoverflow.com/questions/39928051/can-different-threads-write-to-different-sections-of-the-same-vec) – Boiethios Oct 18 '19 at 08:24
  • Possible duplicate of [How can I pass a reference to a stack variable to a thread?](https://stackoverflow.com/questions/32750829/how-can-i-pass-a-reference-to-a-stack-variable-to-a-thread) – trent Oct 18 '19 at 15:27
  • Summary of the duplicate: no. `std` does not expose an API that allows stack references to be shared between threads. There is also `scoped-threadpool` which is considerably smaller in scope than `crossbeam`, if that helps. – trent Oct 18 '19 at 15:30

1 Answers1

0

Maybe split_at_mut or chunks_mut helps.

phimuemue
  • 34,669
  • 9
  • 84
  • 115