Having read a lot of the previous threads on volatile reads and writes using the provided functions on pointers. I came to think if it was possible to have VolatileCellRw<T>, VolatileCellRo<T>, and VolatileCellWo<T>. Where they were respectively implement Deref and DerefMut which could be used with the provided functions (or even better not need then at all).
Would this be enough to guarantee no spurious reads or writes?
Unfortunately, “volatile cell” does not work because you are still using references. A &VolatileCell<T> is still marked as dereferencable and thus the compiler is allowed to introduce spurious reads. As such, the vcell crate is unfortunately not solving this problem.
So this happens even though VolatileCell<T> is wrapping an UnsafeCell<T>? In other words, UnsafeCell<T> prevents the aliasing analysis of a &UnsafeCell<T> to cross the wrapper boundary and be applied to the wrappee, but it does not prevent the dereferenceable attribute from crossing the wrapper boundaries, is that it?
In that case, a new #[lang] wrapper seems to be needed, to act as a barrier on the dereferenceable attribute, is it not?