From: Alice Ryhl <aliceryhl@google.com>
To: boqun.feng@gmail.com
Cc: a.hindborg@samsung.com, alex.gaynor@gmail.com,
aliceryhl@google.com, benno.lossin@proton.me,
bjorn3_gh@protonmail.com, gary@garyguo.net,
linux-kernel@vger.kernel.org, ojeda@kernel.org,
rust-for-linux@vger.kernel.org, walmeida@microsoft.com,
wedsonaf@gmail.com
Subject: Re: [PATCH v2 2/2] rust: arc: remove `ArcBorrow` in favour of `WithRef`
Date: Mon, 25 Sep 2023 15:00:47 +0000 [thread overview]
Message-ID: <20230925150047.1961646-1-aliceryhl@google.com> (raw)
In-Reply-To: <ZRGd4lsNP30L2yB3@Boquns-Mac-mini.home>
>>> I'm concerned about this change, because an `&WithRef<T>` only has
>>> immutable permissions for the allocation. No pointer derived from it
>>> may be used to modify the value in the Arc, however, the drop
>>> implementation of Arc will do exactly that.
>>
>> That is indeed a problem. We could put the value in an `UnsafeCell`, but
>> that would lose us niche optimizations and probably also other optimizations.
>>
>
> Not sure I understand the problem here, why do we allow modifying the
> value in the Arc if you only have a shared ownership?
Well, usually it's when you have exclusive access even though the value
is in an `Arc`.
The main example of this is the destructor of the `Arc`. When the last
refcount drops to zero, this gives you exclusive access. This lets you
run the destructor. The destructor requires mutable access.
Another example would be converting the `Arc` back into an `UniqueArc`
by checking that the refcount is 1. Once you have a `UniqueArc`, you can
use it to mutate the inner value.
Finally, there are methods like `Arc::get_mut_unchecked`, where you
unsafely assert that nobody else is using the value while you are
modifying it. We don't have that in our version of `Arc` right now, but
we might want to add it later.
> Also I fail to see why `ArcBorrow` doesn't have the problem. Maybe I'm
> missing something subtle here? Could you provide an example?
It's because `ArcBorrow` just has a raw pointer inside it. Immutable
references give up write permissions, but raw pointers don't even if
they are `*const T`.
Alice
next prev parent reply other threads:[~2023-09-25 15:00 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-23 14:49 [PATCH v2 0/2] Remove `ArcBorrow` Wedson Almeida Filho
2023-09-23 14:49 ` [PATCH v2 1/2] rust: arc: rename `ArcInner` to `WithRef` Wedson Almeida Filho
2023-09-23 19:31 ` Martin Rodriguez Reboredo
2023-09-24 11:59 ` Benno Lossin
2023-09-24 13:41 ` Jianguo Bao
2023-09-25 6:21 ` Alice Ryhl
2023-09-23 14:49 ` [PATCH v2 2/2] rust: arc: remove `ArcBorrow` in favour of `WithRef` Wedson Almeida Filho
2023-09-23 19:32 ` Martin Rodriguez Reboredo
2023-09-24 11:59 ` Benno Lossin
2023-09-24 13:36 ` Jianguo Bao
2023-09-25 6:29 ` Alice Ryhl
2023-09-25 9:14 ` Benno Lossin
2023-09-25 14:49 ` Boqun Feng
2023-09-25 15:00 ` Alice Ryhl [this message]
2023-09-25 15:17 ` Boqun Feng
2023-09-25 15:30 ` Alice Ryhl
2023-09-25 16:02 ` Boqun Feng
2023-09-25 16:11 ` Benno Lossin
2023-09-25 15:07 ` Benno Lossin
2023-09-25 16:16 ` Boqun Feng
2023-09-25 17:00 ` Benno Lossin
2023-09-25 18:51 ` Boqun Feng
2023-09-25 21:03 ` Benno Lossin
2023-09-25 21:55 ` Boqun Feng
2023-09-25 21:58 ` Alice Ryhl
2023-09-25 22:02 ` Boqun Feng
2023-09-25 22:06 ` Boqun Feng
2023-09-25 22:26 ` Benno Lossin
2023-09-25 22:34 ` Boqun Feng
2023-09-25 23:24 ` Boqun Feng
2023-09-26 8:26 ` Gary Guo
2023-09-26 15:24 ` Boqun Feng
2023-09-26 15:41 ` Alice Ryhl
2023-09-26 16:35 ` Boqun Feng
2023-09-26 17:15 ` Benno Lossin
2023-09-26 17:43 ` Boqun Feng
2023-09-26 18:26 ` Benno Lossin
2023-09-26 21:31 ` Alice Ryhl
2023-09-26 18:20 ` Boqun Feng
2023-09-26 21:27 ` Alice Ryhl
2023-09-25 15:04 ` Alice Ryhl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230925150047.1961646-1-aliceryhl@google.com \
--to=aliceryhl@google.com \
--cc=a.hindborg@samsung.com \
--cc=alex.gaynor@gmail.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=walmeida@microsoft.com \
--cc=wedsonaf@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®