Re: [RFC 2/5] rust: sync: Arc: Introduces ArcInner::count()

From: Josh Stone
Date: Fri Feb 03 2023 - 14:18:40 EST


On 2/2/23 11:38 PM, Greg KH wrote:
> How? Because you have an implicit reference on it already? If so, then
> why does reading from it matter at all, as if you have a reference, you
> know it isn't 0, and that's all that you can really care about. You
> don't care about any number other than 0 for a reference count, as by
> definition, that's what a reference count does :)

There is an additional ability for 1, mentioned up thread -- if you have
&mut Arc<T>, and the inner count is 1, then you *know* there aren't any
other Arc<T> handles anywhere else. Then it is safe to return an
exclusive &mut T, like the upstream Arc::get_mut and Arc::make_mut. This
can also be used for owned Arc<T> like the upstream Arc::try_unwrap.