Description
As tracked in rust-lang/rust#55005, we have a problem with shared references being marked as "dereferencable", in the context of reclamation of memory in concurrent libraries such as Arc
.
I originally thought that not pushing protectors for locations inside UnsafeCell
fixes this, but it does not: if Arc
had a dec
method on ArcInner
that decrements the refcount, then some protectors would get pushed for it (for the part not inside the UnsafeCell
), and get the entire ArcInner
could get deallocated while that method is still running. As @nikomatsakis pointed out, you can even imagine a scenario where the refcount is stored out-of-band, and then there is no UnsafeCell
in the affected allocation at all.
This can, in principle, also happen in sequential code -- imagine RcInner::dec
calling some function after the decrement that might, through an alias, lead to dropping the last remaining aliasing Rc
. Or imagine async code and having a yield point after the decrement but before the function returns.