AtomicReferenceArray in rust


#1

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


#2

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.


#3

I am using a Vec of AtomicPtr now. But I was not too sure if AtomicReferenceArray was equivalent to it.


#4

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.