I implemented quite easily a parallel simple algorithm with 2 threads on an immutable vector, using
Arc<T> as recommended in my previous post.
Now, I’m a little bit lost trying to do the same with a mutable vector. It seems I need to use a
Arc<Mutex<T>>, but maybe it’s not the only solution.
More specifically, what I trying to achieve: if
v length is
n, then I’d like to modify the first half for
[0,n/2[ and the second half for
[n/2, n[ ranges, at the same time from 2 different threads.
crossbeam crate seems to do the job, but I’d like to keep 2 threads alive to achieve this, not starting threads each time I want to loop (which is the way to go for
In my case, a
Mutex will prevent any simultaneous modification for
v, but what can prevent me to modify
v at the same time because both threads will not address the same range ? Compiler optimizations?
Any idea or pointer on something already implemented as an tutorial example ?
Thanks a lot for, as always, your friendly help.