Rust for Linux List
 help / color / mirror / Atom feed
From: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
To: Alice Ryhl <aliceryhl@google.com>,
	Miguel Ojeda <ojeda@kernel.org>,
	Wedson Almeida Filho <wedsonaf@gmail.com>,
	Alex Gaynor <alex.gaynor@gmail.com>
Cc: "Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Will Deacon" <will@kernel.org>,
	"Mark Rutland" <mark.rutland@arm.com>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	patches@lists.linux.dev,
	"Andreas Hindborg" <a.hindborg@samsung.com>
Subject: Re: [PATCH v2 2/4] rust: sync: reword the `Arc` safety comment for `Sync`
Date: Tue, 23 May 2023 13:29:07 -0300	[thread overview]
Message-ID: <c7c3c740-b534-6be1-aead-dc8dbba80882@gmail.com> (raw)
In-Reply-To: <20230523144418.1250547-3-aliceryhl@google.com>

On 5/23/23 11:44, Alice Ryhl wrote:
> The safety comment on `impl Sync for Arc` references the Send safety
> comment. This commit avoids that in case the two comments drift apart in
> the future.
> 
> Suggested-by: Andreas Hindborg <a.hindborg@samsung.com>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com>
> Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
> ---
> [...]
>   
> -// SAFETY: It is safe to send `&Arc<T>` to another thread when the underlying `T` is `Sync` for the
> -// same reason as above. `T` needs to be `Send` as well because a thread can clone an `&Arc<T>`
> -// into an `Arc<T>`, which may lead to `T` being accessed by the same reasoning as above.
> +// SAFETY: It is safe to send `&Arc<T>` to another thread when the underlying `T` is `Sync`
> +// because it effectively means sharing `&T` (which is safe because `T` is `Sync`); additionally,
> +// it needs `T` to be `Send` because any thread that has a `&Arc<T>` may clone it and get an
> +// `Arc<T>` on that thread, so the thread may ultimately access `T` using a mutable reference, for
> +// example, when the reference count reaches zero and `T` is dropped.
>   unsafe impl<T: ?Sized + Sync + Send> Sync for Arc<T> {}
>   
>   impl<T> Arc<T> {

Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>

  parent reply	other threads:[~2023-05-23 16:42 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-23 14:44 [PATCH v2 0/4] Update thread safety markers Alice Ryhl
2023-05-23 14:44 ` [PATCH v2 1/4] rust: sync: reword the `Arc` safety comment for `Send` Alice Ryhl
2023-05-23 15:49   ` Gary Guo
2023-05-23 16:27   ` Martin Rodriguez Reboredo
2023-05-25 13:35   ` Benno Lossin
2023-05-23 14:44 ` [PATCH v2 2/4] rust: sync: reword the `Arc` safety comment for `Sync` Alice Ryhl
2023-05-23 15:50   ` Gary Guo
2023-05-23 17:08     ` Alice Ryhl
2023-05-23 16:29   ` Martin Rodriguez Reboredo [this message]
2023-05-25 13:43   ` Benno Lossin
2023-05-23 14:44 ` [PATCH v2 3/4] rust: specify when `ARef` is thread safe Alice Ryhl
2023-05-23 16:31   ` Martin Rodriguez Reboredo
2023-05-25 13:45     ` Benno Lossin
2023-05-23 14:44 ` [PATCH v2 4/4] rust: task: add `Send` marker to `Task` Alice Ryhl
2023-05-23 15:56   ` Gary Guo
2023-05-23 16:41   ` Martin Rodriguez Reboredo
2023-05-25 13:46   ` Benno Lossin

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=c7c3c740-b534-6be1-aead-dc8dbba80882@gmail.com \
    --to=yakoyoku@gmail.com \
    --cc=a.hindborg@samsung.com \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.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=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=ojeda@kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=peterz@infradead.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=wedsonaf@gmail.com \
    --cc=will@kernel.org \
    /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