I have a massive vector that I want to be able to load / act in parallel, for example. load the first hundreds of thousands of indexes into one stream, the next into another, and so on. Since this will be a very hot part of the code, I came up with the following proof of unsafe concept code to do this without arcs and mutexes:
let mut data:Vec<u32> = vec![1u32, 2, 3]; let head = data.as_mut_ptr(); let mut guards = (0..3).map(|i| unsafe { let mut target = std::ptr::Unique::new(head.offset(i)); let guard = spawn(move || { std::ptr::write(target.get_mut(), 10 + i as u32); }); guard });
Is there anything I missed here that could cause it to explode?
In this case, #![feature(unique)] , so I donβt see how to use this in stable. Is there a way to do such things in a stable way (ideally safe without using the Arc and Mutex pointers and overhead)?
Also, looking at the documentation for Unique , he says
It also means that the pointer reference must not be changed without a unique path to a unique reference.
I do not understand what the "unique path" means.
source share