Re: [PATCH v10 2/2] rust: xarray: Add an abstraction for XArray
From: Tamir Duberstein
Date: Tue Dec 03 2024 - 11:55:36 EST
On Tue, Dec 3, 2024 at 7:16 AM Andreas Hindborg <a.hindborg@xxxxxxxxxx> wrote:
>
> "Tamir Duberstein" <tamird@xxxxxxxxx> writes:
>
> > `XArray` is an efficient sparse array of pointers. Add a Rust
> > abstraction for this type.
> >
> > This implementation bounds the element type on `ForeignOwnable` and
> > requires explicit locking for all operations. Future work may leverage
> > RCU to enable lockless operation.
> >
> > Inspired-by: Maíra Canal <mcanal@xxxxxxxxxx>
> > Inspired-by: Asahi Lina <lina@xxxxxxxxxxxxx>
> > Signed-off-by: Tamir Duberstein <tamird@xxxxxxxxx>
> > ---
>
> [cut]
>
> > +
> > +// SAFETY: It is safe to send `XArray<T>` to another thread when the underlying `T` is `Send`
> > +// because XArray is thread-safe and all mutation operations are synchronized.
> > +unsafe impl<T: ForeignOwnable + Send> Send for XArray<T> {}
> > +
> > +// SAFETY: It is safe to send `&XArray<T>` to another thread when the underlying `T` is `Sync`
> > +// because it effectively means sharing `&T` (which is safe because `T` is `Sync`). Additionally,
> > +// `T` is `Send` because XArray is thread-safe and all mutation operations are internally locked.
> > +unsafe impl<T: ForeignOwnable + Send + Sync> Sync for XArray<T> {}
>
> I don't understand the sentence: "Additionally, `T` is `Send` because XArray is
> thread-safe and all mutation operations are internally locked.", could
> you elaborate?
This comment came from the original series, I'll reword it in the next version.