Add element-wise atomic memory operations by tmccombs · Pull Request #59155 · rust-lang/rust (original) (raw)

Sure thing! In Fuchsia, we often have two processes that communicate by sharing memory. If the two processes are mutually-distrusting, then, when operating on that shared memory, they each need to assume that the other is maliciously modifying the memory concurrently. From the perspective of the memory model, this is identical to another thread in the same process modifying the memory. Thus, to avoid UB, we can only operate on the memory using atomic operations. Our approach is very simple - copy all of the data into a separate part of the address space which is not shared, and then operate on it. Originally, we did this using a loop of Relaxed atomic loads, but that turned out to perform really poorly. Thus, we're hoping that these intrinsics - which have the guarantees that we need from a concurrency perspective - will perform better.