Atomic operations in Rust

I have a question regarding atomic operations in rust, looking at the docs for AtomicPtr, I can see that I can do all kinds of atomic operations on the atomicptr type itself, but I can't use atomic operations on raw pointers without using intrinsics (which require nightly).

Is it highly unsafe to make the atomic_compare_exchange free function and others like it, public?

Yes, it is unsafe, because then you have no guarantee that everyone everywhere consistently uses atomic operations on the same data.

6 Likes

Also, it's unsound to do atomic ops on a &*const T -- to change something behind a reference it needs to be inside an UnsafeCell (as AtomicPtr does).

3 Likes