lkml.org 
[lkml]   [2023]   [May]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH v2 4/4] rust: task: add `Send` marker to `Task`
From
On 5/23/23 11:44, Alice Ryhl wrote:
> When a type also implements `Sync`, the meaning of `Send` is just "this
> type may be accessed mutably from threads other than the one it is
> created on". That's ok for this type.
>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com>
> ---
> [...]
>
> -// SAFETY: It's OK to access `Task` through references from other threads because we're either
> -// accessing properties that don't change (e.g., `pid`, `group_leader`) or that are properly
> +// SAFETY: By design, the only way to access a `Task` is via the `current` function or via an
> +// `ARef<Task>` obtained through the `AlwaysRefCounted` impl. This means that the only situation in
> +// which a `Task` can be accessed mutably is when the refcount drops to zero and the destructor
> +// runs. It is safe for that to happen on any thread, so it is ok for this type to be `Send`.
> +unsafe impl Send for Task {}
> +
> +// SAFETY: It's OK to access `Task` through shared references from other threads because we're
> +// either accessing properties that don't change (e.g., `pid`, `group_leader`) or that are properly
> // synchronised by C code (e.g., `signal_pending`).
> unsafe impl Sync for Task {}
>

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

\
 
 \ /
  Last update: 2023-05-23 18:43    [W:0.144 / U:0.680 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site