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.
To solve the problem with volatile references, we need either a wrapper around a raw pointer – something like VolatileRef<'a, T>
which is basically a newtype around NonNull<T>
; or we need a language change to no longer allow spurious dereferences of all references. Note that this does not just affect volatile accesses, we also have a case in libstd that is in conflict with this.
Also see this UCG discussion.