Is there a equivalent of AtomicReferenceArray in rust in std or any crate?
https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/atomic/AtomicReferenceArray.html
Is there a equivalent of AtomicReferenceArray in rust in std or any crate?
https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/atomic/AtomicReferenceArray.html
An array (or Vec or slice) of AtomicPtr
would be equivalent. Java's AtomicReferenceArray is simply a wrapper around a plain Object array with read/write access implemented using Unsafe. You could have an array of AtomicReference in Java as well, but that creates more bloat because AtomicReference itself is an object. Rust doesn't have this problem.
I am using a Vec of AtomicPtr now. But I was not too sure if AtomicReferenceArray was equivalent to it.
I recently had a need for this so I created the atomic-array crate which mirrors the AtomicXXXArray
classes from Java.
This does use AtomicPtr
internally but its wrapped in a safe API.